On this page:
Internet Media Types
media-type
string->media-type
media-type-subtype-tree
media-type-subtype-facets
media-type-vendor-tree?
media-type-personal-tree?
media-type-private-tree?
media-type-experimental-tree?
media-type-has-facets?
media-type-has-suffix?
media-type-has-parameters?
media-type->string
1.0

Internet Media Types🔗ℹ

Simon Johnston <johnstonskj@gmail.com>

This package provides types and predicates for testing internet media types.

A media type (formerly known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. Their purpose is somewhat similar to file extensions in that they identify the intended data format. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication of these classifications.

mime-type := type "/" sub-type ["+" suffix] [";" parameter]*

sub-type  := [tree "."] subtype

parameter := param-name "=" param-value

 

type      := restricted-name

tree      := restricted-name

subtype   := restricted-name + "."

param-name := restricted-name + ":" "+" "."

struct

(struct media-type (type subtype suffix parameters))

  type : media-type-type-string?
  subtype : (listof media-type-subtype-facet-string?)
  suffix : (or/c media-type-subtype-suffix-string? #f)
  parameters : 
(hash/c media-type-parameter-name-string?
        media-type-parameter-value-string?)
TBD

constructor

(string->media-type str)  media-type?

  str : string?
TBD

Example:
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml")))
    (displayln mt)
    (displayln (media-type-type mt))
    (displayln (media-type-subtype mt))
    (displayln (media-type-suffix mt))
    (displayln (media-type-parameters mt)))

#(struct:media-type application (vnd 3gpp crs) xml #hash())

application

(vnd 3gpp crs)

xml

#hash()

TBD

Example:
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml")))
    (displayln (media-type-subtype mt))
    (displayln (media-type-subtype-tree mt)))

(vnd 3gpp crs)

vnd

TBD

Example:
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml")))
    (displayln (media-type-subtype mt))
    (displayln (media-type-subtype-facets mt)))

(vnd 3gpp crs)

(3gpp crs)

predicate

(media-type-vendor-tree? mt)  boolean?

  mt : media-type?
TBD

Example:
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml")))
    (displayln (media-type-vendor-tree? mt)))

#t

predicate

(media-type-personal-tree? mt)  boolean?

  mt : media-type?
TBD

Example:
> (let ((mt (string->media-type "application/prs.implied-object+json")))
    (displayln (media-type-personal-tree? mt)))

#t

predicate

(media-type-private-tree? mt)  boolean?

  mt : media-type?
TBD

predicate

(media-type-experimental-tree? mt)  boolean?

  mt : media-type?
TBD

Example:
> (let ((mt (string->media-type "multipart/x-mixed-replace")))
    (displayln (media-type-experimental-tree? mt)))

#t

predicate

(media-type-has-facets? mt)  boolean?

  mt : media-type?
TBD

Example:
> (let ((mt (string->media-type "application/prs.implied-object+json")))
    (displayln (media-type-has-facets? mt)))

#t

predicate

(media-type-has-suffix? mt)  boolean?

  mt : media-type?
TBD

Example:
> (let ((mt (string->media-type "application/prs.implied-object+json")))
    (displayln (media-type-has-suffix? mt)))

#t

predicate

(media-type-has-parameters? mt)  boolean?

  mt : media-type?
TBD

Example:
> (let ((mt (string->media-type "text/plain;charset=UTF-8")))
    (displayln (media-type-has-parameters? mt)))

#t

procedure

(media-type->string mt)  string?

  mt : media-type?
TBD

Example:
> (displayln
   (media-type->string
    (string->media-type "application/prs.implied-object+json")))

application/prs.implied-object+json