aiohug
Project description
aiohug
======
|pipeline status| |coverage report|
.. |pipeline status| image:: https://gitlab.com/nonamenix/aiohug/badges/master/pipeline.svg
:target: https://gitlab.com/nonamenix/aiohug/commits/master
.. |coverage report| image:: https://gitlab.com/nonamenix/aiohug/badges/master/coverage.svg
:target: https://gitlab.com/nonamenix/aiohug/commits/master
Goals:
=====
- Unpack aiohttp request to arguments with annotations
- Validate handlers arguments
- Generate swagger specification
Examples
========
Run ping pong application
-------------------------
.. code:: python
from aiohttp import web
from aiohug import RouteTableDef
routes = RouteTableDef()
@routes.get("/ping/")
async def ping():
return "pong"
app = web.Application()
app.add_routes(routes)
if __name__ == "__main__":
web.run_app(app)
There is no more ``request`` object in handler.
Arguments from path and query
-----------------------------
.. code:: python
@routes.get("/hello/{name}/")
async def hello(name: fields.String(), greeting: fields.String() = "Hello"):
return {"msg": f"{greeting}, {name}"}
Body with schema
----------------
.. code:: python
from aiohttp import web
from aiohug import RouteTableDef
routes = RouteTableDef()
class PayloadSchema(Schema):
count = fields.Int()
@routes.get("/")
async def with_body(body: PayloadSchema()):
return body
app = create_app()
app.add_routes(routes)
client = await test_client(app)
resp = await client.get("/", json={"count": "5", "another": 7})
assert await resp.json() == {"count": 5}
Another shortcuts
-----------------
.. code:: python
@routes.post("/ping/")
async def ping():
return 201, "pong"
Swagger
-------
Use `aiohug_swagger` package.
Why aiohug?
===========
It's just hug_ API implementation for aiohttp
.. _hug: https://github.com/timothycrosley/hug
TODO:
=====
- don’t pass default arguments
- default websocket handler with ping/pong and schemas support
.. code:: python
ws = aiohug.WSHandler()
@ws("hello") # match message by `type` field
async def hello(name: str, greeting: str="Hi"):
""" Just send {"type": "hello", "name": "Lucy", "greeting": "Hi"} """
return {"text", f"{greeting}, {name}"}
app = create_app()
app.add_routes([web.get('/ws', ws)])
======
|pipeline status| |coverage report|
.. |pipeline status| image:: https://gitlab.com/nonamenix/aiohug/badges/master/pipeline.svg
:target: https://gitlab.com/nonamenix/aiohug/commits/master
.. |coverage report| image:: https://gitlab.com/nonamenix/aiohug/badges/master/coverage.svg
:target: https://gitlab.com/nonamenix/aiohug/commits/master
Goals:
=====
- Unpack aiohttp request to arguments with annotations
- Validate handlers arguments
- Generate swagger specification
Examples
========
Run ping pong application
-------------------------
.. code:: python
from aiohttp import web
from aiohug import RouteTableDef
routes = RouteTableDef()
@routes.get("/ping/")
async def ping():
return "pong"
app = web.Application()
app.add_routes(routes)
if __name__ == "__main__":
web.run_app(app)
There is no more ``request`` object in handler.
Arguments from path and query
-----------------------------
.. code:: python
@routes.get("/hello/{name}/")
async def hello(name: fields.String(), greeting: fields.String() = "Hello"):
return {"msg": f"{greeting}, {name}"}
Body with schema
----------------
.. code:: python
from aiohttp import web
from aiohug import RouteTableDef
routes = RouteTableDef()
class PayloadSchema(Schema):
count = fields.Int()
@routes.get("/")
async def with_body(body: PayloadSchema()):
return body
app = create_app()
app.add_routes(routes)
client = await test_client(app)
resp = await client.get("/", json={"count": "5", "another": 7})
assert await resp.json() == {"count": 5}
Another shortcuts
-----------------
.. code:: python
@routes.post("/ping/")
async def ping():
return 201, "pong"
Swagger
-------
Use `aiohug_swagger` package.
Why aiohug?
===========
It's just hug_ API implementation for aiohttp
.. _hug: https://github.com/timothycrosley/hug
TODO:
=====
- don’t pass default arguments
- default websocket handler with ping/pong and schemas support
.. code:: python
ws = aiohug.WSHandler()
@ws("hello") # match message by `type` field
async def hello(name: str, greeting: str="Hi"):
""" Just send {"type": "hello", "name": "Lucy", "greeting": "Hi"} """
return {"text", f"{greeting}, {name}"}
app = create_app()
app.add_routes([web.get('/ws', ws)])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file aiohug-0.4.0.dev37772126.tar.gz
.
File metadata
- Download URL: aiohug-0.4.0.dev37772126.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed0bc977610ba2c110671dd4956892405425f5578dfac2f054592c95f3bcbfa3 |
|
MD5 | eeec547b4fd729cf9ea21b41e32224da |
|
BLAKE2b-256 | 378ce096021eeda36baac66ec46c42b4ef90713942acb3ef6a6e1a20558330c5 |