-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ nav: | |
- doses/10.md | ||
- doses/11.md | ||
- doses/12.md | ||
- doses/13.md | ||
|
||
markdown_extensions: | ||
- attr_list: | ||
|