diff --git a/docs/en/docs/tutorial/http-query.md b/docs/en/docs/tutorial/http-query.md index a2ed698a7..c3843abaf 100644 --- a/docs/en/docs/tutorial/http-query.md +++ b/docs/en/docs/tutorial/http-query.md @@ -1,4 +1,4 @@ -# HTTP QUERY +# HTTP QUERY { #http-query } Typically, when you want to read data you use `GET`. If you need to send complex data (like a large JSON object) to filter that data, you traditionally had to use `POST` because `GET` requests does not support request bodies. @@ -6,7 +6,7 @@ However, using `POST` for read-only operations isn't semantically correct, as `P There is a newer HTTP method called **QUERY**. It is designed exactly for this: performing safe, idempotent read operations that require a request body. -## Using `QUERY` +## Using `QUERY` { #using-query } In **FastAPI**, you can use the `QUERY` method using the `@app.query()` decorator. @@ -15,16 +15,15 @@ It works similarly to `@app.post()`, allowing you to receive Pydantic models in {* ../../docs_src/http_query/tutorial001.py hl[7] *} -### Testing it +### Testing it { #testing-it } You can test it using an HTTP client that supports the `QUERY` method. Because it allows a body, you can send complex filters without hitting URL length limits common with `GET` query parameters. -### Technical Details +### Technical Details { #technical-details } The `QUERY` method is defined in the [IETF HTTP QUERY Method Draft](https://www.ietf.org/archive/id/draft-ietf-httpbis-safe-method-w-body-02.html). It is considered: * **Safe**: It does not alter the state of the server (read-only). * **Idempotent**: Making the same request multiple times yields the same result. - diff --git a/docs_src/http_query/tutorial001.py b/docs_src/http_query/tutorial001.py index 2fd51acd0..5c29adcd9 100644 --- a/docs_src/http_query/tutorial001.py +++ b/docs_src/http_query/tutorial001.py @@ -14,4 +14,4 @@ class ItemSearch(BaseModel): @app.query("/items/") async def search_items(search_params: ItemSearch): - return {"message": "Searching items", "search_params": search_params} \ No newline at end of file + return {"message": "Searching items", "search_params": search_params} diff --git a/tests/test_tutorial/test_http_query/test_tutorial001.py b/tests/test_tutorial/test_http_query/test_tutorial001.py index 5a29d2f0f..01df2719b 100644 --- a/tests/test_tutorial/test_http_query/test_tutorial001.py +++ b/tests/test_tutorial/test_http_query/test_tutorial001.py @@ -29,4 +29,7 @@ def test_openapi_schema(): assert "query" in schema["paths"]["/items/"] operation = schema["paths"]["/items/"]["query"] assert "requestBody" in operation - assert "ItemSearch" in operation["requestBody"]["content"]["application/json"]["schema"]["$ref"] + assert ( + "ItemSearch" + in operation["requestBody"]["content"]["application/json"]["schema"]["$ref"] + )