cro-mediatype

Cro::MediaType

The Cro::MediaType class provides a range of functionality relating to media types, including parsing them into their parts or serializing them from their parts.

Parsing a media type

To parse a media type, pass it to the parse method:

my $media-type = Cro::MediaType.parse('content/html; charset=UTF-8');

This results a Cro::MediaType instance.

Extracting parts of the media type

Consider an example media type application/vnd.foobar+json; charset=UTF-8. The following methods are available for extracting parts of the media type:

  • type - returns application

  • subtype - returns vnd.foobar+json

  • tree - returns vnd

  • subtype-name - returns foobar

  • suffix - returns json

  • type-and-subtype - returns application/vnd.foobar+json

  • parameters - returns an Array containing a Pair; in the example given, charset => 'UTF-8'

Constructing a media type from parts

The new method can be called to construct a media type from its parts. The type and subtype-name named parameters are required; tree, suffix, and parameters may be optionally provided.

Serializing a media type

Stringify a Cro::MediaType object to turn it into a string representation of the media type.

my $media-type = Cro::MediaType.new:
    type => 'application',
    tree => 'vnd',
    subtype-name => 'foobar',
    suffix => 'json',
    parameters => [charset => 'UTF-8'];

say ~$media-type;   # application/vnd.foobar+json; charset=UTF-8

cro v0.8.8

Libraries and tools for building reactive services in Raku. This installs the cro command line and web tool, along with HTTP (including HTTPS and HTTP/2.0) and WebSocket support.

Authors

  • Jonathan Worthington

License

Artistic-2.0

Dependencies

IO::Socket::Async::SSLJSON::FastMETA6Shell::CommandFile::FindTerminal::ANSIColorOO::MonitorsYAMLishCro::WebSocket:ver<0.8.8>Docker::FileFile::Ignore

Test Dependencies

Provides

  • Cro::Tools::CLI
  • Cro::Tools::CroFile
  • Cro::Tools::Link::Editor
  • Cro::Tools::LinkTemplate
  • Cro::Tools::LinkTemplate::HTTP
  • Cro::Tools::LinkTemplate::HTTPS
  • Cro::Tools::LinkTemplate::WS
  • Cro::Tools::LinkTemplate::WSS
  • Cro::Tools::Runner
  • Cro::Tools::Serve
  • Cro::Tools::Services
  • Cro::Tools::Template
  • Cro::Tools::Template::Common
  • Cro::Tools::Template::HTTPService
  • Cro::Tools::Template::ReactReduxSPA
  • Cro::Tools::Template::ZeroMQWorkSinkService
  • Cro::Tools::Template::ZeroMQWorkerService
  • Cro::Tools::TemplateLocator
  • Cro::Tools::Web

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.