A collection of basic Content-Types (also known as Internet Media
Types, or MIME types). Additionally, this module provides classes that
encapsulate how to serialize or deserialize values to or from a
particular Content-Type.
Content-Types are used in
ReqBody and the method combinators:
>>> type MyEndpoint = ReqBody '[JSON, PlainText] Book :> Put '[JSON, PlainText] Book
Meaning the endpoint accepts requests of Content-Type
application/json or
text/plain;charset=utf8, and
returns data in either one of those formats (depending on the
Accept header).
If you would like to support Content-Types beyond those provided here,
then:
- Declare a new data type with no constructors (e.g. data
HTML).
- Make an instance of it for Accept.
- If you want to be able to serialize data *into* that Content-Type,
make an instance of it for MimeRender.
- If you want to be able to deserialize data *from* that
Content-Type, make an instance of it for MimeUnrender.
Note that roles are reversed in
servant-server and
servant-client: to be able to serve (or even typecheck) a
Get '[JSON, XML] MyData, you'll need to have the appropriate
MimeRender instances in scope, whereas to query that endpoint
with
servant-client, you'll need a
MimeUnrender
instance in scope.