2015-08-19 22:29:32 +00:00
|
|
|
API Documentation
|
|
|
|
=================
|
2021-10-01 12:35:10 +00:00
|
|
|
|
2015-11-03 13:10:54 +00:00
|
|
|
.. currentmodule:: sprockets.mixins.mediatype.content
|
2015-08-19 22:29:32 +00:00
|
|
|
|
2021-10-01 12:35:10 +00:00
|
|
|
The easiest way to use this library is to:
|
|
|
|
|
|
|
|
#. call :func:`.install` when you create your application instance and specify a
|
|
|
|
default content type
|
|
|
|
#. call :func:`.add_transcoder` to install transcoders for the content types that
|
|
|
|
you support -- use :func:`.add_binary_content_type` and/or
|
|
|
|
:func:`.add_text_content_type` if you don't want to define a
|
|
|
|
:class:`~sprockets.mixins.mediatype.type_info.Transcoder` class.
|
|
|
|
#. include :class:`.ContentMixin` in your handler's inheritance chain
|
|
|
|
#. call :meth:`~.ContentMixin.get_request_body` to retrieve a request body
|
|
|
|
sent in any of the supported content types
|
|
|
|
#. call :meth:`~.ContentMixin.send_response` to send a response in any of the
|
|
|
|
supported content types
|
|
|
|
|
|
|
|
The :class:`.ContentMixin` will take care of inspecting the :http:header:`Content-Type`
|
|
|
|
header and deserialize the request as well as implementing the
|
|
|
|
:rfc:`proactive content negotiation algorithm <7231#section-3.4.1>` described in
|
|
|
|
:rfc:`7231` to serialize a response object appropriately.
|
|
|
|
|
2015-08-19 22:29:32 +00:00
|
|
|
Content Type Handling
|
|
|
|
---------------------
|
|
|
|
.. autoclass:: ContentMixin
|
|
|
|
:members:
|
|
|
|
|
|
|
|
Content Type Registration
|
|
|
|
-------------------------
|
2016-04-03 11:41:15 +00:00
|
|
|
.. autofunction:: install
|
|
|
|
|
2021-10-01 12:35:10 +00:00
|
|
|
.. autofunction:: add_transcoder
|
2016-04-03 11:41:15 +00:00
|
|
|
|
2015-08-19 22:29:32 +00:00
|
|
|
.. autofunction:: set_default_content_type
|
|
|
|
|
|
|
|
.. autofunction:: add_binary_content_type
|
|
|
|
|
|
|
|
.. autofunction:: add_text_content_type
|
|
|
|
|
2021-10-01 12:35:10 +00:00
|
|
|
.. autofunction:: get_settings
|
2016-01-10 18:51:14 +00:00
|
|
|
|
2015-08-19 22:29:32 +00:00
|
|
|
.. autoclass:: ContentSettings
|
2015-06-08 20:28:30 +00:00
|
|
|
:members:
|
2016-01-10 19:46:27 +00:00
|
|
|
|
|
|
|
Bundled Transcoders
|
|
|
|
-------------------
|
|
|
|
.. currentmodule:: sprockets.mixins.mediatype.transcoders
|
|
|
|
|
|
|
|
.. autoclass:: JSONTranscoder
|
|
|
|
:members:
|
2016-01-13 12:28:44 +00:00
|
|
|
|
|
|
|
.. autoclass:: MsgPackTranscoder
|
|
|
|
:members:
|
2021-10-01 12:35:10 +00:00
|
|
|
|
|
|
|
.. _type-info:
|
|
|
|
|
|
|
|
Python Type Information
|
|
|
|
-----------------------
|
|
|
|
The ``sprockets.mixins.mediatype.type_info`` module contains a number of
|
|
|
|
convenience type definitions for those you you who take advantage of type
|
|
|
|
annotations.
|
|
|
|
|
|
|
|
.. currentmodule:: sprockets.mixins.mediatype.type_info
|
|
|
|
|
|
|
|
Interface Types
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. autoclass:: Transcoder
|
|
|
|
:members:
|
|
|
|
|
|
|
|
.. autodata:: Serializable
|
|
|
|
|
|
|
|
.. autodata:: Deserialized
|
|
|
|
|
|
|
|
Convenience Types
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. autodata:: PackBFunction
|
|
|
|
|
|
|
|
.. autodata:: UnpackBFunction
|
|
|
|
|
|
|
|
.. autodata:: DumpSFunction
|
|
|
|
|
|
|
|
.. autodata:: LoadSFunction
|
|
|
|
|
|
|
|
Contract Types
|
|
|
|
~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. autoclass:: HasSettings
|
|
|
|
:members:
|
|
|
|
|
|
|
|
.. autoclass:: DefinesIsoFormat
|
|
|
|
:members:
|