You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,6 @@ The key features are:
49
49
<ahref="https://bit.ly/3dmXC5S"target="_blank"title="The data structure for unstructured multimodal data"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/docarray.svg"></a>
50
50
<ahref="https://bit.ly/3JJ7y5C"target="_blank"title="Build cross-modal and multimodal applications on the cloud"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/jina2.svg"></a>
51
51
<ahref="https://cryptapi.io/"target="_blank"title="CryptAPI: Your easy to use, secure and privacy oriented payment gateway."><imgsrc="https://fastapi.tiangolo.com/img/sponsors/cryptapi.svg"></a>
52
-
<ahref="https://app.imgwhale.xyz/"target="_blank"title="The ultimate solution to unlimited and forever cloud storage."><imgsrc="https://fastapi.tiangolo.com/img/sponsors/imgwhale.svg"></a>
53
52
<ahref="https://doist.com/careers/9B437B1615-wa-senior-backend-engineer-python"target="_blank"title="Help us migrate doist to FastAPI"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/doist.svg"></a>
54
53
<ahref="https://www.deta.sh/?ref=fastapi"target="_blank"title="The launchpad for all your (team's) ideas"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/deta.svg"></a>
55
54
<ahref="https://www.investsuite.com/jobs"target="_blank"title="Wealthtech jobs with FastAPI"><imgsrc="https://fastapi.tiangolo.com/img/sponsors/investsuite.svg"></a>
Copy file name to clipboardExpand all lines: docs/en/docs/advanced/custom-response.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,12 @@ For example, if you are squeezing performance, you can install and use <a href="
21
21
22
22
Import the `Response` class (sub-class) you want to use and declare it in the *path operation decorator*.
23
23
24
+
For large responses, returning a `Response` directly is much faster than returning a dictionary.
25
+
26
+
This is because by default, FastAPI will inspect every item inside and make sure it is serializable with JSON, using the same [JSON Compatible Encoder](../tutorial/encoder.md){.internal-link target=_blank} explained in the tutorial. This is what allows you to return **arbitrary objects**, for example database models.
27
+
28
+
But if you are certain that the content that you are returning is **serializable with JSON**, you can pass it directly to the response class and avoid the extra overhead that FastAPI would have by passing your return content through the `jsonable_encoder` before passing it to the response class.
@@ -244,6 +250,36 @@ You can also use the `response_class` parameter:
244
250
245
251
In this case, you can return the file path directly from your *path operation* function.
246
252
253
+
## Custom response class
254
+
255
+
You can create your own custom response class, inheriting from `Response` and using it.
256
+
257
+
For example, let's say that you want to use <ahref="https://github.com/ijl/orjson"class="external-link"target="_blank">`orjson`</a>, but with some custom settings not used in the included `ORJSONResponse` class.
258
+
259
+
Let's say you want it to return indented and formatted JSON, so you want to use the orjson option `orjson.OPT_INDENT_2`.
260
+
261
+
You could create a `CustomORJSONResponse`. The main thing you have to do is create a `Response.render(content)` method that returns the content as `bytes`:
Copy file name to clipboardExpand all lines: docs/en/docs/release-notes.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,14 @@
2
2
3
3
## Latest Changes
4
4
5
+
* ♻ Internal small refactor, move `operation_id` parameter position in delete method for consistency with the code. PR [#4474](https://github.com/tiangolo/fastapi/pull/4474) by [@hiel](https://github.com/hiel).
6
+
* ✨ Support Python internal description on Pydantic model's docstring. PR [#3032](https://github.com/tiangolo/fastapi/pull/3032) by [@Kludex](https://github.com/Kludex).
7
+
* ✨ Update `ORJSONResponse` to support non `str` keys and serializing Numpy arrays. PR [#3892](https://github.com/tiangolo/fastapi/pull/3892) by [@baby5](https://github.com/baby5).
8
+
* 🔧 Update sponsors, disable ImgWhale. PR [#5338](https://github.com/tiangolo/fastapi/pull/5338) by [@tiangolo](https://github.com/tiangolo).
9
+
* 📝 Update docs for `ORJSONResponse` with details about improving performance. PR [#2615](https://github.com/tiangolo/fastapi/pull/2615) by [@falkben](https://github.com/falkben).
10
+
* 📝 Add docs for creating a custom Response class. PR [#5331](https://github.com/tiangolo/fastapi/pull/5331) by [@tiangolo](https://github.com/tiangolo).
11
+
* 📝 Add tip about using alias for form data fields. PR [#5329](https://github.com/tiangolo/fastapi/pull/5329) by [@tiangolo](https://github.com/tiangolo).
12
+
* 🐛 Fix support for path parameters in WebSockets. PR [#3879](https://github.com/tiangolo/fastapi/pull/3879) by [@davidbrochart](https://github.com/davidbrochart).
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/request-forms.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ For example, in one of the ways the OAuth2 specification can be used (called "pa
27
27
28
28
The <abbrtitle="specification">spec</abbr> requires the fields to be exactly named `username` and `password`, and to be sent as form fields, not JSON.
29
29
30
-
With `Form` you can declare the same metadata and validation as with `Body` (and `Query`, `Path`, `Cookie`).
30
+
With `Form` you can declare the same configurations as with `Body` (and `Query`, `Path`, `Cookie`), including validation, examples, an alias (e.g. `user-name` instead of `username`), etc.
31
31
32
32
!!! info
33
33
`Form` is a class that inherits directly from `Body`.
0 commit comments