https://github.com/gr1n/aioapi
Yet another way to build APIs using AIOHTTP framework
https://github.com/gr1n/aioapi
aiohttp aiohttp-server annotations api apis typing
Last synced: 11 months ago
JSON representation
Yet another way to build APIs using AIOHTTP framework
- Host: GitHub
- URL: https://github.com/gr1n/aioapi
- Owner: Gr1N
- License: mit
- Created: 2018-11-11T20:34:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-14T14:06:57.000Z (almost 6 years ago)
- Last Synced: 2025-03-18T21:16:50.206Z (11 months ago)
- Topics: aiohttp, aiohttp-server, annotations, api, apis, typing
- Language: Python
- Homepage: https://gr1n.github.io/aioapi/
- Size: 845 KB
- Stars: 13
- Watchers: 4
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aioapi
[](https://github.com/Gr1N/aioapi/actions?query=workflow%3Adefault) [](https://codecov.io/gh/Gr1N/aioapi)   
Yet another way to build APIs using [`AIOHTTP`](https://aiohttp.readthedocs.io/) framework.
Follow [documentation](https://gr1n.github.io/aioapi/) to know what you can do with `AIOAPI`.
## Installation
```sh
$ pip install aioapi
```
## Usage & Examples
Below you can find a simple, but powerful example of `AIOAPI` library usage:
```python
import aioapi as api
from aioapi import Body, PathParam
from aioapi.middlewares import validation_error_middleware
from aiohttp import web
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int = 42
async def hello_body(user_id: PathParam[int], body: Body[User]):
user = body.cleaned
return web.json_response(
{"id": user_id.cleaned, "name": user.name, "age": user.age}
)
def main():
app = web.Application()
app.add_routes([api.post("/hello/{user_id}", hello_body)])
app.middlewares.append(validation_error_middleware)
web.run_app(app)
if __name__ == "__main__":
main()
```
And there are also more examples of usage at [`examples/`](https://github.com/Gr1N/aioapi/tree/master/example) directory.
To run them use command below:
```sh
$ make example
```
## Contributing
To work on the `AIOAPI` codebase, you'll want to clone the project locally and install the required dependencies via [poetry](https://poetry.eustace.io):
```sh
$ git clone git@github.com:Gr1N/aioapi.git
$ make install
```
To run tests and linters use command below:
```sh
$ make lint && make test
```
If you want to run only tests or linters you can explicitly specify what you want to run, e.g.:
```sh
$ make lint-black
```
## Milestones
If you're interesting in project's future you can find milestones and plans at [projects](https://github.com/Gr1N/aioapi/projects) page.
## License
`AIOAPI` is licensed under the MIT license. See the license file for details.