Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qweeze/nanoasgi
A toy ASGI web framework
https://github.com/qweeze/nanoasgi
asgi asyncio python
Last synced: 1 day ago
JSON representation
A toy ASGI web framework
- Host: GitHub
- URL: https://github.com/qweeze/nanoasgi
- Owner: qweeze
- License: unlicense
- Created: 2020-12-02T18:08:13.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-21T18:28:46.000Z (almost 4 years ago)
- Last Synced: 2024-08-02T17:33:45.383Z (3 months ago)
- Topics: asgi, asyncio, python
- Language: Python
- Homepage:
- Size: 6.84 KB
- Stars: 20
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-asgi - nanoasgi - A tiny zero-dependency ASGI web framework. (Resources / Experiments and examples)
README
### nanoasgi
This is a toy ASGI web framework. It has zero dependencies and only 170 lines of code. I wrote it to play around with ASGI and to study how frameworks work under the hood.
Python >= 3.7 is required.#### Example:
```python
# example.py
from nanoasgi import Appapp = App()
@app.on('startup')
async def on_startup():
print('Ready to serve requests')@app.on('shutdown')
async def on_shutdown():
print('Shutting down')@app.route('GET', '/api/hello/{name}/')
async def hello_handler(request, name):
return Response(
{'result': f'Hello {name}!'},
status=200,
headers=[('Content-Type', 'application/json')],
)
```
```bash
$ uvicorn example:app
```