Skip to main content

Rapid rest resources for aiohttp

Project description

Rapid rest resources for aiohttp

Latest PyPI package version

Key Features

  • Supports both client and server side of HTTP protocol.

Getting started

aiorestapi allows you to quickly create a rest resource in a few steps. It automatically creates the resource routes on the collections or individual items; it's simply to specify the suffix '_collection' or '_item' on the methods. The serialization / deserialization of results / requests occurs transparently using python dictionaries.

An example creating a simple rest resource

from aiohttp import web
from aiorestapi import RestView, routes

@routes.resource("/views")
class RestResource(RestView):

    # example call: GET to <server>/views?start=10
    async def on_get_collection(self, start=0) -> list:
        return [
            {"id": int(start)+1, "value": 1},
            {"id": int(start)+2, "value": 2},
        ]

    # example call: GET <server>/views/80
    async def on_get_item(self, id: str) -> dict:
        return self.key

    # example call: POST to <server>/views
    async def on_post_collection(self, body: dict) -> dict:
        return body


app = web.Application()
app.add_routes(routes)
app['key'] = [1, 2, 4, 5]

if __name__ == '__main__':
    web.run_app(app)

Installation

It's very simple to install aiorestapi:

pip install aiorestapi

Notes

  • @routes.resource decorator the decorator automatically adds the routes to '/myresources' and '/myresources/{id}'
  • From the RestView object it is possible to access the aiohttp request with self.request
  • The query parameters are automatically converted into parameters of the view method.
  • If requests have a body it is necessary to specify in the method a parameter called 'body'
  • If requests are to the single item it is necessary to specify a parameter called 'id'
  • The items stored as 'app[]' are accessible into view as properties 'self.'

To Do

  • Tests!!
  • Documentation
  • Configurable custom serializers/deserializers

Requirements

License

aiorestapi is offered under the Apache 2 license.

Source code

The latest developer version is available in a GitHub repository: https://github.com/aiselis/aiorestapi

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

aiorestapi-0.1.2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

aiorestapi-0.1.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file aiorestapi-0.1.2.tar.gz.

File metadata

  • Download URL: aiorestapi-0.1.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.0

File hashes

Hashes for aiorestapi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bb9380122c14886dc7c9a4d88eb7862ed93f400f0e6e2a1691be0441ffc35cc8
MD5 e096cfbd5a1d883a950df0d40e6dcc76
BLAKE2b-256 b462d902dcac436c3990342969e1b230bd4eb3f724b20e0467147b9ecc993846

See more details on using hashes here.

File details

Details for the file aiorestapi-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aiorestapi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.0

File hashes

Hashes for aiorestapi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8227451e69c16c2f043300cc30db8a9e770279e24804cb1c9f2419f2cdb21f34
MD5 4562c84dce48bc53aa31833810c25082
BLAKE2b-256 371f3453deaee231e2613334a24b7b073049a1c30baba7a4d9f69a417fa988f2

See more details on using hashes here.

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