Skip to content

Commit 3811ae0

Browse files
committed
Add dose 13
1 parent 96f63d2 commit 3811ae0

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

code/13/quart_example.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Any
2+
3+
from quart import Quart, request
4+
5+
app = Quart(__name__)
6+
7+
8+
@app.post("/my-endpoint")
9+
async def my_endpoint() -> dict[str, Any]:
10+
request_json = await request.get_json()
11+
return {"echoed data": request_json}
12+
13+
14+
#######################################
15+
# Let's test it
16+
import pytest
17+
18+
19+
@pytest.mark.asyncio
20+
async def test_my_endpoint() -> None:
21+
client = app.test_client()
22+
23+
response = await client.post("/my-endpoint", json={"foo": "bar"})
24+
25+
assert response.status_code == 200
26+
response_data = await response.get_json()
27+
assert response_data == {"echoed data": {"foo": "bar"}}

code/13/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
quart==0.17.0
2+
3+
pytest==7.1.1
4+
pytest-asyncio==0.18.3

docs/doses/13.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: 13 - Quart
3+
tags:
4+
- Interesting projects
5+
- Web
6+
---
7+
# 13 - Quart
8+
Quart is an ASGI re-implementation of the Flask API with some added ASGI specific features, such as websockets.
9+
If you have a Flask project and would like to go truly async, migrating to Quart is an option.
10+
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.
11+
12+
13+
![TODO](../img/13.png)
14+
15+
??? info "Read more"
16+
* Docs: [https://quart.palletsprojects.com/en/latest/index.html](https://quart.palletsprojects.com/en/latest/index.html)
17+
* GitHub repo: [https://github.com/pallets/quart](https://github.com/pallets/quart)
18+
* Quart became part of Pallets: [https://palletsprojects.com/blog/quart-pallets/](https://palletsprojects.com/blog/quart-pallets/)
19+
20+
??? tip "The code"
21+
```python
22+
--8<-- "code/13/quart_example.py"
23+
```
24+
25+
tested with:
26+
```
27+
--8<-- "code/13/requirements.txt"
28+
```
29+
30+
Run the server:
31+
```
32+
QUART_APP=quart_example:app quart run
33+
```
34+
35+
Or just the test case:
36+
```
37+
pytest quart_example.py
38+
```

docs/img/13.png

248 KB
Loading

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ nav:
4040
- doses/10.md
4141
- doses/11.md
4242
- doses/12.md
43+
- doses/13.md
4344

4445
markdown_extensions:
4546
- attr_list:

0 commit comments

Comments
 (0)