Skip to content

Commit

Permalink
Add dose 13
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-git committed Jul 7, 2022
1 parent 96f63d2 commit 3811ae0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
27 changes: 27 additions & 0 deletions code/13/quart_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Any

from quart import Quart, request

app = Quart(__name__)


@app.post("/my-endpoint")
async def my_endpoint() -> dict[str, Any]:
request_json = await request.get_json()
return {"echoed data": request_json}


#######################################
# Let's test it
import pytest


@pytest.mark.asyncio
async def test_my_endpoint() -> None:
client = app.test_client()

response = await client.post("/my-endpoint", json={"foo": "bar"})

assert response.status_code == 200
response_data = await response.get_json()
assert response_data == {"echoed data": {"foo": "bar"}}
4 changes: 4 additions & 0 deletions code/13/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quart==0.17.0

pytest==7.1.1
pytest-asyncio==0.18.3
38 changes: 38 additions & 0 deletions docs/doses/13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: 13 - Quart
tags:
- Interesting projects
- Web
---
# 13 - Quart
Quart is an ASGI re-implementation of the Flask API with some added ASGI specific features, such as websockets.
If you have a Flask project and would like to go truly async, migrating to Quart is an option.
Quart recently became a Pallets project (the folks behind Flask, Click, Jinja, etc) and they apparently intend to merge Quart and Flask to eventually have ASGI support in Flask.


![TODO](../img/13.png)

??? info "Read more"
* Docs: [https://quart.palletsprojects.com/en/latest/index.html](https://quart.palletsprojects.com/en/latest/index.html)
* GitHub repo: [https://github.com/pallets/quart](https://github.com/pallets/quart)
* Quart became part of Pallets: [https://palletsprojects.com/blog/quart-pallets/](https://palletsprojects.com/blog/quart-pallets/)

??? tip "The code"
```python
--8<-- "code/13/quart_example.py"
```

tested with:
```
--8<-- "code/13/requirements.txt"
```

Run the server:
```
QUART_APP=quart_example:app quart run
```

Or just the test case:
```
pytest quart_example.py
```
Binary file added docs/img/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nav:
- doses/10.md
- doses/11.md
- doses/12.md
- doses/13.md

markdown_extensions:
- attr_list:
Expand Down

0 comments on commit 3811ae0

Please sign in to comment.