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.
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)
). Themedia_type.ContentMixin
adds methods to retrieve the decoded request body and to encode and write adict
to the response stream. Both methods use the registered content types and appropriate HTTP headers to determine how to handle the request and response.