Skip to content

Media Types Reference

TMediaType (MARS.Core.MediaType) defines constants for the common MIME types used in [Produces] / [Consumes] and content negotiation. Prefer these constants over string literals.

pascal
[GET, Produces(TMediaType.APPLICATION_JSON)]
function GetData: TData;

Constants

ConstantValue
TMediaType.TEXT_PLAINtext/plain
TMediaType.TEXT_XMLtext/xml
TMediaType.TEXT_HTMLtext/html
TMediaType.TEXT_YAMLtext/yaml
TMediaType.TEXT_EVENT_STREAMtext/event-stream
TMediaType.APPLICATION_XMLapplication/xml
TMediaType.APPLICATION_XML_FireDACapplication/xml-firedac
TMediaType.APPLICATION_JSONapplication/json
TMediaType.APPLICATION_JSON_FireDACapplication/json-firedac
TMediaType.APPLICATION_XHTML_XMLapplication/xhtml+xml
TMediaType.APPLICATION_SVG_XMLapplication/svg+xml
TMediaType.APPLICATION_ATOM_XMLapplication/atom+xml
TMediaType.APPLICATION_OCTET_STREAMapplication/octet-stream
TMediaType.APPLICATION_FORM_URLENCODED_TYPEapplication/x-www-form-urlencoded
TMediaType.APPLICATION_YAMLapplication/x-yaml
TMediaType.APPLICATION_PDFapplication/pdf
TMediaType.MULTIPART_FORM_DATAmultipart/form-data
TMediaType.WILDCARD*/*

Notes

  • */* (WILDCARD) matches any type; writers/readers registered for it act as fallbacks (lowest affinity).
  • FireDAC variants (…-firedac) carry datasets in a compact Delphi-native format; plain application/json carries them as an interoperable array of objects. See FireDAC & Datasets.
  • text/event-stream is used by Server-Sent Events.
  • application/x-yaml requires MARS.YAML.ReadersAndWriters to be registered (used by the OpenAPI endpoint).

Parsing and matching

TMediaType.Create('application/json;charset=utf-8') parses a header value (type, subtype and parameters such as charset and quality factor q). Matches performs content-type negotiation, honoring wildcards and q priorities — this is what the content-negotiation layer uses to pick a reader/writer against the request's Accept/Content-Type.

Released under the Apache License 2.0.