Arbitrator¶
Tornado mix-in to simplify HTTP Content Type negotation and serilization.
Installation¶
Arbitrator is available on the Python Package Index and can be installed via pip or easy_install:
pip install arbitrator
Requirements¶
- tornado
Simple Example¶
>>> import json
>>> import msgpack
>>> from tornado import web
>>> class MyHandler(arbitrator.MediaTypeMixn, web.RequestHandler):
...
... def initalize(self):
... media_types = {
... 'application/json': json,
... 'application/msgpack': msgpack,
... 'application/x-msgpack': msgpack
... }
... super(MyHandler, self).initalize(supported_media_types=media_types)
...
... def get(self, account_id):
... payload = self.load_payload(
... self.request.headers['Content-Type'],
... self.request.content,
... )
... # ... do stuff with the payload dictionary
... content_type, stringified = self.dump_payload(
... self.request.headers['Accept'],
... payload,
... )
... self.set_status(200)
... self.set_header('Content-Type', content_type)
... self.finish(stringified)
API Documentation¶
Version History¶
See Release History
Contributing¶
If you want to help make this project better you are officially an awesome person.
Pull requests or Github issues are always welcome. If you want to contribute a patch please do the following.
- Fork this repo and create a new branch
- Do work
- Add tests for your work (Mandatory)
- Submit a pull request
- Wait for Coveralls and Travis-CI to run through your PR
- I’ll review it and merge it
As a note, code without sufficient tests will not be merged.
Issues¶
Please report any issues to the Github project at https://github.com/djt5019/arbitrator/issues
Source¶
Arbitrator source is available on Github at https://github.com/djt5019/arbitrator
License¶
Arbitrator is released under the MIT license.