sprockets / sprockets.mixins.mediatype

Handles Content-Type & Accept header serialization and deserialization for you
https://sprocketsmixinsmedia-type.readthedocs.io
BSD 3-Clause "New" or "Revised" License
0 stars 3 forks source link

Initial implementation #2

Closed dave-shawley closed 9 years ago

dave-shawley commented 9 years ago

This PR implements a slightly different approach than the original documented method. The basic idea is that each content type and with it's encoding & decoding methods are registered on the tornado.web.Application instance using a set of free-functions (e.g., media_type.add_text_content_type(application, 'application/json', 'utf-8', json.dumps, json.loads)). The media_type.ContentMixin adds methods to retrieve the decoded request body and to encode and write a dict to the response stream. Both methods use the registered content types and appropriate HTTP headers to determine how to handle the request and response.