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
`CreateDogSerializer`, a pydantic type, so fields(`name`, `age`, `breed`) validations according to defined types and
260
268
specifications is supported out of the box. It's important to note the way we used `CreateDogSerializer` as a type annotation to `payload` parameter in `create` method.
261
269
During request Ellar computes the route handler signatures and validates them to the annotated types before executing the handler.
Copy file name to clipboardExpand all lines: docs/overview/middleware.md
+11-5Lines changed: 11 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ This is how to apply any `ASGI` middlewares such as `GZipMiddleware`, `EllarASGI
101
101
## Starlette Middlewares
102
102
Let's explore other Starlette middlewares and other third party ASGI Middlewares
103
103
104
-
-### `GZipMiddleware`
104
+
### `GZipMiddleware`
105
105
Handles GZip responses for any request that includes "gzip" in the Accept-Encoding header.
106
106
The middleware will handle both standard and streaming responses.
107
107
@@ -121,11 +121,12 @@ class DevelopmentConfig(BaseConfig):
121
121
```
122
122
123
123
The following arguments are supported:
124
+
124
125
-`minimum_size` - Do not GZip responses that are smaller than this minimum size in bytes. Defaults to `500`.
125
126
126
127
The middleware won't GZip responses that already have a Content-Encoding set, to prevent them from being encoded twice.
127
128
128
-
-### `HTTPSRedirectMiddleware`
129
+
### `HTTPSRedirectMiddleware`
129
130
Enforces that all incoming requests must either be `https` or `wss`.
130
131
131
132
Any incoming requests to `http` or `ws` will be redirected to the secure scheme instead.
@@ -144,7 +145,8 @@ class DevelopmentConfig(BaseConfig):
144
145
]
145
146
146
147
```
147
-
-### `TrustedHostMiddleware`
148
+
149
+
### `TrustedHostMiddleware`
148
150
This middleware is already part of ellar application middlewares. The middleware takes an argument `allowed_host` which can be configured in the configuration class.
149
151
150
152
@@ -165,10 +167,11 @@ To allow any hostname either use `allowed_hosts=["*"]` or omit the middleware.
165
167
166
168
If an incoming request does not validate correctly then a `400` response will be sent.
167
169
168
-
-### `CORSMiddleware`
170
+
### `CORSMiddleware`
169
171
Adds appropriate [`CORS headers`](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) to outgoing responses in order to allow cross-origin requests from browsers.
170
172
171
173
Since `CORSMiddleware` is part of default application middleware, let's see how to configure CORS arguments in ellar application.
174
+
172
175
```python
173
176
# project_name/config.py
174
177
import typing as t
@@ -187,7 +190,9 @@ class DevelopmentConfig(BaseConfig):
187
190
CORS_MAX_AGE: int=600
188
191
189
192
```
193
+
190
194
The following arguments are supported:
195
+
191
196
-`CORS_ALLOW_ORIGINS` - A list of origins that should be permitted to make cross-origin requests. eg. `['https://example.org', 'https://www.example.org']`. You can use `['*']` to allow any origin.
192
197
-`CORS_ALLOW_ORIGIN_REGEX` - A regex string to match against origins that should be permitted to make cross-origin requests. eg. `'https://.*\.example\.org'`.
193
198
-`CORS_ALLOW_METHODS` - A list of HTTP methods that should be allowed for cross-origin requests. Defaults to `['GET']`. You can use `['*']` to allow all standard methods.
@@ -209,10 +214,11 @@ The middleware responds to two particular types of HTTP request
209
214
Any request with an `Origin` header. In this case the middleware will pass the request through as normal, but will include appropriate CORS headers on the response.
Copy file name to clipboardExpand all lines: docs/overview/providers.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,10 @@
1
1
A provider is any class or object that is **injectable** as a dependency to another class, and it's required when creating an instance of that class.
2
+
2
3
So, in a way, providers are like services, repositories, factories etc., classes that can manage complex tasks.
3
4
This concept of class injection is known as [Dependency Injector](https://de.wikipedia.org/wiki/Dependency_Injection)
4
5
5
6
You can easily create a provider class by decorating that class with the `@injectable()` mark
7
+
6
8
```python
7
9
from ellar.di import injectable, singleton_scope
8
10
@@ -88,7 +90,7 @@ class DogsController(ControllerBase):
88
90
We have defined `DogsRepository` as a dependency to `DogsController` which means Ellar will resolve `DogsRepository` instance when creating `DogsController` instance.
89
91
This was made possible by type definition on `dog_repo` parameter and with the type defined, Ellar knows the provider to look for.
90
92
91
-
!!info
93
+
!!! info
92
94
Every class dependencies should be defined in the class **constructor**, that way Ellar will resolve all the dependencies needed for an object instantiation.
0 commit comments