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
Each route handler has its own `ResponseModel` computation and validation. If there is no response definition, Ellar default the route handler model to `EmptyAPIResponseModel`.
63
63
64
64
65
-
## Override Response Type
65
+
## **Override Response Type**
66
66
67
67
When you use a `Response` class as response, a `ResponseModel` is used and the `response_type` is replaced with applied response class.
68
68
@@ -96,7 +96,7 @@ from ellar.common import PlainTextResponse
Copy file name to clipboardExpand all lines: docs/handling-response/response.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
## Introduction
1
+
## **Response and Serializers**
2
2
The `Serializer` class in the Ellar, is a custom class based on `pydantic` models, which provides additional functionality specific to Ellar's requirements.
3
3
4
4
To use `Serializer` in Ellar, you simply need to create a class that inherits from `Serializer` and define your data model using pydantic fields.
@@ -17,7 +17,7 @@ class UserSerializer(Serializer):
17
17
With this setup, you can use the `UserSerializer` class to validate incoming data and or serialize outgoing response data,
18
18
ensuring that it matches the expected format before saving it to the database or returning it to the client.
19
19
20
-
## Handling Responses
20
+
## **Handling Responses**
21
21
22
22
Let's see how we can use **Serializer** as a responses schema which will help us validate out data output and also provide documentation on route function response.
23
23
@@ -71,7 +71,7 @@ that can be easily serialized to JSON.
71
71
The resulting dictionary is then passed to the [`JSONResponseModel`](./response-model/#jsonresponsemodel) for serialization to a
72
72
JSON string and sending the response to the client.
73
73
74
-
## Using Dataclass as Response Schema
74
+
## **Using Dataclass as Response Schema**
75
75
We can utilize the `dataclasses` feature as a response schema by utilizing the `DataclassSerializer` a base class.
76
76
77
77
For instance, we can convert the `UserSchema` to a dataclass by defining `UserDataclass` as follows:
@@ -92,7 +92,7 @@ class UserDataclass(DataclassSerializer):
92
92
93
93
By replacing the `UserSchema` with `UserDataclass`, we can expect the same outcomes in the returned response, response validation, and documentation.
94
94
95
-
### Multiple Response Types
95
+
### **Multiple Response Types**
96
96
97
97
The `response` parameter takes different shape. Let's see how to return a different response if the user is not authenticated.
98
98
@@ -156,7 +156,7 @@ Here, the `response` parameter takes a KeyValuePair of the `status` and response
156
156
157
157
158
158
159
-
## Using Response Type/Object As Response
159
+
## **Using Response Type/Object As Response**
160
160
161
161
You can use `Response` type to change the format of data returned from endpoint functions.
Copy file name to clipboardExpand all lines: docs/parsing-inputs/body.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Request Body
1
+
# **Request Body**
2
2
3
3
Request bodies are typically used with “create” and “update” operations (POST, PUT, PATCH).
4
4
For example, when creating a resource using POST or PUT, the request body usually contains the representation of the resource to be created.
@@ -8,7 +8,7 @@ To declare a **request body**, you need to use **Ellar `Serializer`**.
8
8
!!! info
9
9
Under the hood **Ellar** uses <ahref="https://pydantic-docs.helpmanual.io/"class="external-link"target="_blank">Pydantic</a> models with all their power and benefits.
10
10
11
-
## Import Serializer
11
+
## **Import Serializer**
12
12
13
13
First, you need to import `Serializer` from `ella.serializer`:
14
14
@@ -24,7 +24,7 @@ from ellar.common import Serializer
24
24
25
25
```
26
26
27
-
## Create your data model
27
+
## **Create your data model**
28
28
29
29
Then you declare your data model as a class that inherits from `Serializer`.
30
30
@@ -71,7 +71,7 @@ For example, this model above declares a JSON "`object`" (or Python `dict`) like
71
71
}
72
72
```
73
73
74
-
## Declare it as a parameter
74
+
## **Declare it as a parameter**
75
75
76
76
To add it to your *path operation*, declare it the same way you declared the path and query parameters:
77
77
@@ -97,7 +97,7 @@ class ItemsController(ControllerBase):
97
97
98
98
... and declare its type as the model you created, `Item`.
99
99
100
-
## Results
100
+
## **Results**
101
101
102
102
With just that Python type declaration, **Ellar** will:
103
103
@@ -112,7 +112,7 @@ With just that Python type declaration, **Ellar** will:
112
112
your models, and you can also use them anywhere else you like if it makes sense for your project.
113
113
* Those schemas will be part of the generated OpenAPI schema, and used by the automatic documentation <abbrtitle="User Interfaces">UI's</abbr>.
114
114
115
-
## Automatic Docs
115
+
## **Automatic Docs**
116
116
117
117
The JSON Schemas of your models will be part of your OpenAPI generated schema, and will be shown in the interactive API docs:
118
118
@@ -123,7 +123,7 @@ The JSON Schemas of your models will be part of your OpenAPI generated schema, a
123
123

124
124
125
125
126
-
## Request Body + Path parameters
126
+
## **Request Body + Path parameters**
127
127
128
128
You can declare path parameters **and** body requests at the same time.
129
129
@@ -152,7 +152,7 @@ class ItemsController(ControllerBase):
152
152
return {"item_id": item_id, "item": item.dict()}
153
153
```
154
154
155
-
## Request Body + Path + Query parameters
155
+
## **Request Body + Path + Query parameters**
156
156
157
157
You can also declare **body**, **path** and **query** parameters, all at the same time.
158
158
@@ -191,7 +191,7 @@ The function parameters will be recognized as follows:
191
191
In here, we have combined both `Serializers` and `Controllers` in one file. This is for the convenience of writing this documentation.
192
192
It's advised to have all your serializers in `schemas.py` and then import them over to `controllers.py` if needed.
193
193
194
-
## Singular values in body
194
+
## **Singular values in body**
195
195
The same way there is a `Query` and `Path` to define extra data for query and path parameters,
196
196
**Ellar** provides an equivalent `Body`.
197
197
@@ -253,7 +253,7 @@ In this case, **Ellar** will expect a body like:
253
253
}
254
254
```
255
255
256
-
## Multiple body params and query
256
+
## **Multiple body params and query**
257
257
Of course, you can also declare additional `query` parameters whenever you need, additional to anybody parameters.
258
258
259
259
As, by default, singular values are interpreted as query parameters, you don't have to explicitly add a `Query`, you can just do:
Copy file name to clipboardExpand all lines: docs/parsing-inputs/file-params.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# File uploads
1
+
# **File Uploads**
2
2
3
3
Handling files are no different from other parameters.
4
4
You can define files to be uploaded by using `File`.
@@ -10,11 +10,11 @@ You can define files to be uploaded by using `File`.
10
10
11
11
This is because uploaded files are sent as "form data".
12
12
13
-
## Import `File`
13
+
## **Import `File`**
14
14
15
15
First import `File` from `ellar.common` module
16
16
17
-
## Define `File` parameters
17
+
## **Define `File` parameters**
18
18
19
19
Create file parameters the same way you would for `Body` or `Form`:
20
20
@@ -38,7 +38,7 @@ Have in mind that this means that the whole contents will be stored in memory. T
38
38
39
39
But there are several cases in which you might benefit from using `UploadFile`.
40
40
41
-
## `File` parameters with `UploadFile`
41
+
## **`File` parameters with `UploadFile`**
42
42
43
43
Define a `File` parameter with a type of `UploadFile`:
44
44
@@ -106,7 +106,7 @@ contents = myfile.file.read()
106
106
**Ellar**'s `UploadFile` inherits directly from **Starlette**'s `UploadFile`, but adds some necessary parts to make it compatible with **Pydantic** and the other parts of Ellar.
107
107
108
108
109
-
## Uploading array of files
109
+
## **Uploading array of files**
110
110
111
111
To **upload several files** at the same time, just declare a `List` of `UploadFile`:
112
112
@@ -124,7 +124,7 @@ class ItemsController(ControllerBase):
124
124
return [f.filename for f in files]
125
125
```
126
126
127
-
## Uploading files with extra fields
127
+
## **Uploading files with extra fields**
128
128
129
129
Note: HTTP protocol does not allow you to send files in application/json format by default (unless you encode it somehow to JSON on client side)
0 commit comments