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
feat: rename FromFile and File to FromRawBody and RawBody (#117)
We're keeping backwards compatibility aliases which will be removed in a future release, so this should have no impact on existing code but we recommend the new names going forward.
Copy file name to clipboardExpand all lines: docs/tutorial/body.md
+17-2Lines changed: 17 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,14 +57,14 @@ First, import `Field` from Pydantic and `Annotated`:
57
57
All it does is import `Annotated` from `typing` if your Python version is >= 3.9 and [typing_extensions] otherwise.
58
58
But if you are already using Python >= 3.9, you can just replace that with `from typing import Annotated`.
59
59
60
-
Now use `Field()` inside of `Annotated[...]` to attach validation and schema customziation metadata to the `price` field:
60
+
Now use `Field()` inside of `Annotated[...]` to attach validation and schema customization metadata to the `price` field:
61
61
62
62
```python hl_lines="11-17"
63
63
--8<--"docs_src/tutorial/body/tutorial_002.py"
64
64
```
65
65
66
66
!!! tip "Tip"
67
-
Pydantic also supports the syntax `field_name: str = Field(...)`, but we encourage youto get used to using `Annotated` instead.
67
+
Pydantic also supports the syntax `field_name: str = Field(...)`, but we encourage you to get used to using `Annotated` instead.
68
68
As you will see in later chapters about forms and multipart requests, this will allow you to mix in Pydantic's validation and schema customization with Xpresso's extractor system.
69
69
That said, for JSON bodies using `field_name: str = Field(...)` will work just fine.
70
70
@@ -97,4 +97,19 @@ The Swagger docs will now reflect this:
97
97
98
98

99
99
100
+
## Raw bytes
101
+
102
+
To extract the raw bytes from the body (without validating it as JSON) see [Files](files.md).
103
+
104
+
## Consuming of the request body
105
+
106
+
By default Xpresso will _consume_ the request body.
107
+
This is the equivalent of calling `Request.steam()` until completion.
108
+
When you only need to extract the body once this is probably what you want since it avoids keeping around extra memory that goes unused.
109
+
If you want to extract the request body and still have access to it in another extractor or via `Request` you need to set `consume=False` as an argument to `Json`:
Copy file name to clipboardExpand all lines: docs/tutorial/files.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Files
2
2
3
-
You can read the request body directly into a file or bytes.
3
+
You can read the raw request body directly into a file or bytes.
4
4
This will read the data from the top level request body, and can only support 1 file.
5
5
To receive multiple files, see the [multipart/form-data documentation].
6
6
@@ -35,7 +35,7 @@ If you want to read the bytes without buffering to disk or memory, use `AsyncIte
35
35
36
36
## Setting the expected content-type
37
37
38
-
You can set the media type via the `media_type` parameter to `File()` and enforce it via the `enforce_media_type` parameter:
38
+
You can set the media type via the `media_type` parameter to `RawBody()` and enforce it via the `enforce_media_type` parameter:
39
39
40
40
```python
41
41
--8<--"docs_src/tutorial/files/tutorial_004.py"
@@ -44,6 +44,6 @@ You can set the media type via the `media_type` parameter to `File()` and enforc
44
44
Media types can be a media type (e.g. `image/png`) or a media type range (e.g. `image/*`).
45
45
46
46
If you do not explicitly set the media type, all media types are accepted.
47
-
Once you set an explicit media type, that media type in the requests' `Content-Type` header will be validated on incoming requests, but this behavior can be disabled via the `enforce_media_type` parameter to `File()`.
47
+
Once you set an explicit media type, that media type in the requests' `Content-Type` header will be validated on incoming requests, but this behavior can be disabled via the `enforce_media_type` parameter to `RawBody()`.
0 commit comments