Skip to main content

REST tools in python - common code for client and server

Project description

PyPI GitHub release (latest by date including pre-releases) PyPI - License Lines of code GitHub issues GitHub pull requests

rest-tools

This project contains REST tools in python, as common code for multiple other projects under https://github.com/WIPACrepo.

All code uses python asyncio, so is fully asyncronous.

Note that both the client and server assume starting the asyncio loop happens elsewhere - they do not start the loop themselves.

Client

A REST API client exists under rest_tools.client. Use as:

    from rest_tools.client import RestClient

    api = RestClient('http://my.site.here/api', token='XXXX')
    ret = await api.request('GET', '/fruits/apple')
    ret = await api.request('POST', '/fruits', {'name': 'banana'})

Server

A REST API server exists under rest_tools.server. Use as:

    import asyncio
    from rest_tools.server import RestServer, RestHandler

    class Fruits(RestHandler):
        def post(self):
            # handle a new fruit
            self.write({})

    server = RestServer()
    server.add_route('/fruits', Fruits)
    server.startup(address='my.site.here', port=8080)
    asyncio.get_event_loop().run_forever()

The server uses Tornado to handle HTTP connections. It is recommended to use Apache or Nginx as a front-facing proxy, to handle TLS sessions and non-standard HTTP requests in production.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wipac-rest-tools-1.4.9.tar.gz (26.2 kB view hashes)

Uploaded Source

Built Distribution

wipac_rest_tools-1.4.9-py3-none-any.whl (31.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page