The http-media package

[Tags: library, mit]

This library is intended to be a comprehensive solution to parsing and selecting quality-indexed values in HTTP headers. It is capable of parsing both media types and language parameters from the Accept and Content header families, and can be extended to match against other accept headers as well. Selecting the appropriate header value is achieved by comparing a list of server options against the quality-indexed values supplied by the client.

In the following example, the Accept header is parsed and then matched against a list of server options to serve the appropriate media using mapAcceptMedia:

 getHeader >>= maybe send406Error sendResourceWith . mapAcceptMedia
     [ ("text/html",        asHtml)
     , ("application/json", asJson)
     ]

Similarly, the Content-Type header can be used to produce a parser for request bodies based on the given content type with mapContentMedia:

 getContentType >>= maybe send415Error readRequestBodyWith . mapContentMedia
     [ ("application/json", parseJson)
     , ("text/plain",       parseText)
     ]

The API is agnostic to your choice of server.

Properties

Versions0.1.0, 0.1.1, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.6.2
Change logNone available
Dependenciesbase (>=4.6 && <5.0), bytestring (==0.10.*), case-insensitive (>=1.0 && <1.3), containers (==0.5.*) [details]
LicenseMIT
Copyright(c) 2012-2015 Timothy Jones
AuthorTimothy Jones
MaintainerTimothy Jones <git@zmthy.io>
CategoryWeb
Home pagehttps://github.com/zmthy/http-media
Bug trackerhttps://github.com/zmthy/http-media/issues
Source repositoryhead: git clone git://github.com/zmthy/http-media.git
UploadedTue May 5 06:14:44 UTC 2015 by TimothyJones
DistributionsLTSHaskell:0.6.2, NixOS:0.6.2, Stackage:0.6.2
Downloads3000 total (390 in last 30 days)
Votes
0 []
StatusDocs available [build log]
Last success reported on 2015-05-05 [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees