Skip to content

Commit 78bce02

Browse files
committed
Doc md error fixes
1 parent 4623a13 commit 78bce02

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

docs/overview/controllers.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ For example, a path prefix of `/users` combined with the decorator `@get('/profi
7474
`GET /users/profile`.
7575

7676

77-
Overview of HTTP function decorator parameters:
77+
#### Overview of HTTP function decorator parameters:
7878

7979
`@get(path: str, name: str, include_in_schema: bool, response: t.Union[t.Dict[int, t.Type], t.List[t.Tuple[int, t.Type]], t.Type])`
80+
8081
- `path`: defines path for route mapping. `default='/'`
8182
- `name`: defines a `name` that will be used to identify this route during URL reversing. default is function name eg: `get_all`
8283
- `include_in_schema`: indicates if an endpoint should be available in OPENAPI docs
@@ -108,6 +109,7 @@ class DogsController(ControllerBase):
108109
```
109110

110111
- injection (`parameter_name=Req()`)
112+
111113
We can also inject request object to any handler by using `@Req` decorator in handler signature.
112114
```python
113115
# project_name/apps/dogs/controllers.py
@@ -127,6 +129,7 @@ class DogsController(ControllerBase):
127129
```
128130

129131
- controllers context
132+
130133
During request handler execution, `Execution Context` is available on the Controller instance and `request` object can be gotten from the context.
131134
```python
132135
# project_name/apps/dogs/controllers.py
@@ -162,6 +165,7 @@ Other request `handler` signature injectors
162165
| `Provide()` | injects services |
163166

164167
## Resource
168+
165169
Let add create endpoint to our `DogsController` resource.
166170
```python
167171
# project_name/apps/dogs/controllers.py
@@ -181,7 +185,9 @@ class DogsController(ControllerBase):
181185
return 'This action returns all dogs'
182186
...
183187
```
188+
184189
### HTTP Methods
190+
185191
Ellar provides decorators for all the standard HTTP methods:
186192
- `@get` - `GET` HTTP method
187193
- `@post` - `POST` HTTP method
@@ -195,6 +201,7 @@ Ellar provides decorators for all the standard HTTP methods:
195201

196202

197203
## Asynchronicity
204+
198205
Ellar support modern asynchronous programming in python using `async` and `await` syntax.
199206

200207
```python
@@ -216,6 +223,7 @@ class DogsController(ControllerBase):
216223
...
217224
```
218225
## Request Payload
226+
219227
Let's use `@Body()` to defined required data to create a dog in our previous `create`(POST) endpoint.
220228
Before that, we need to define our data input/output serializers
221229

@@ -259,7 +267,8 @@ async def create(self, payload: CreateDogSerializer = Body()):
259267
`CreateDogSerializer`, a pydantic type, so fields(`name`, `age`, `breed`) validations according to defined types and
260268
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.
261269
During request Ellar computes the route handler signatures and validates them to the annotated types before executing the handler.
262-
![CreateDogSchema](img/create-dog-schema.png)
270+
271+
![CreateDogSchema](../img/create-dog-schema.png)
263272

264273
Let's add other endpoints
265274

@@ -327,4 +336,4 @@ class DogsModule(ModuleBase):
327336
pass
328337
```
329338

330-
![controller_dog.gif](img/controller_dog.gif)
339+
![controller_dog.gif](../img/controller_dog.gif)

docs/overview/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ with features that covers a lot of ground at an introductory level.
55

66
## Library Dependencies
77
Ellar core depends on:
8+
89
- `python >= 3.7`
910
- `Starlette`
1011
- `Injector`
@@ -70,6 +71,7 @@ Both provides all necessary parameter for creating Ellar application
7071

7172
## Run your project
7273
Ellar runs [UVICORN - ASGI Server](https://www.uvicorn.org/) under the hood.
74+
7375
```shell
7476
$(venv) cd project-name
7577
$(venv) ellar runserver --reload

docs/overview/middleware.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ This is how to apply any `ASGI` middlewares such as `GZipMiddleware`, `EllarASGI
101101
## Starlette Middlewares
102102
Let's explore other Starlette middlewares and other third party ASGI Middlewares
103103

104-
- ### `GZipMiddleware`
104+
### `GZipMiddleware`
105105
Handles GZip responses for any request that includes "gzip" in the Accept-Encoding header.
106106
The middleware will handle both standard and streaming responses.
107107

@@ -121,11 +121,12 @@ class DevelopmentConfig(BaseConfig):
121121
```
122122

123123
The following arguments are supported:
124+
124125
- `minimum_size` - Do not GZip responses that are smaller than this minimum size in bytes. Defaults to `500`.
125126

126127
The middleware won't GZip responses that already have a Content-Encoding set, to prevent them from being encoded twice.
127128

128-
- ### `HTTPSRedirectMiddleware`
129+
### `HTTPSRedirectMiddleware`
129130
Enforces that all incoming requests must either be `https` or `wss`.
130131

131132
Any incoming requests to `http` or `ws` will be redirected to the secure scheme instead.
@@ -144,7 +145,8 @@ class DevelopmentConfig(BaseConfig):
144145
]
145146

146147
```
147-
- ### `TrustedHostMiddleware`
148+
149+
### `TrustedHostMiddleware`
148150
This middleware is already part of ellar application middlewares. The middleware takes an argument `allowed_host` which can be configured in the configuration class.
149151

150152

@@ -165,10 +167,11 @@ To allow any hostname either use `allowed_hosts=["*"]` or omit the middleware.
165167

166168
If an incoming request does not validate correctly then a `400` response will be sent.
167169

168-
- ### `CORSMiddleware`
170+
### `CORSMiddleware`
169171
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.
170172

171173
Since `CORSMiddleware` is part of default application middleware, let's see how to configure CORS arguments in ellar application.
174+
172175
```python
173176
# project_name/config.py
174177
import typing as t
@@ -187,7 +190,9 @@ class DevelopmentConfig(BaseConfig):
187190
CORS_MAX_AGE: int = 600
188191

189192
```
193+
190194
The following arguments are supported:
195+
191196
- `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.
192197
- `CORS_ALLOW_ORIGIN_REGEX` - A regex string to match against origins that should be permitted to make cross-origin requests. eg. `'https://.*\.example\.org'`.
193198
- `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
209214
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.
210215

211216

212-
- ### `Other Middlewares`
217+
### `Other Middlewares`
213218

214219
There are many other ASGI middlewares.
215220
For example:
221+
216222
- [Sentry](https://docs.sentry.io/platforms/python/asgi/)
217223
- [Uvicorn's ProxyHeadersMiddleware](https://github.com/encode/uvicorn/blob/master/uvicorn/middleware/proxy_headers.py)
218224
- [MessagePack](https://github.com/florimondmanca/msgpack-asgi)

docs/overview/modules.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ the internal data structure used to resolve module and provider relationships an
3232
The best way to organize your components is to build your projects as `Modules`.
3333
Thus, the architecture resulting from most applications will include multiple modules with closely related **functionality**.
3434

35-
# `Feature modules`
35+
## `Feature modules`
3636
Module helps to organize code relevant for specific features, ensuring that the code is clear and organized.
3737
This will help to manage complexity and develop using SOLID especially as the application or team grows.
3838

@@ -60,7 +60,7 @@ class DogsModule(ModuleBase):
6060
pass
6161
```
6262

63-
# `Module Parameters`
63+
## `Module Parameters`
6464
Let's create a Module and take a quick overview of its parameters.
6565

6666
```python
@@ -95,8 +95,8 @@ class BookModule(ModuleBase):
9595
| `static_folder` | defines the static folder for this module |
9696
| `template_folder` | defines the template folder for this module |
9797

98-
# `Additional Module Configurations`
99-
- ## `Module Events`
98+
## `Additional Module Configurations`
99+
### `Module Events`
100100
Every registered Module receives two event calls during its instantiation and when application is ready.
101101

102102
```python
@@ -115,7 +115,7 @@ class ModuleEventSample(ModuleBase):
115115
```
116116
`before_init` receives current app `Config` as a parameter and `application_ready` function receives `App` instance as parameter.
117117

118-
- ## `Module Exceptions`
118+
### `Module Exceptions`
119119
In Ellar, custom exceptions can be registered through modules.
120120
During module meta-data computation, Ellar reads additional properties such as these from registered modules
121121

@@ -131,7 +131,7 @@ class ModuleExceptionSample(ModuleBase):
131131
```
132132
`exception_404_handler` will be register to the application at runtime during `ModuleExceptionSample` computation.
133133

134-
- ## `Module Templating Filters`
134+
### `Module Templating Filters`
135135
We can also define `Jinja2` templating filters in project Modules or any `@Module()` module.
136136
The defined filters are be passed down to `Jinja2` **environment** instance alongside the `template_folder`
137137
value when creating **TemplateLoader**.
@@ -155,7 +155,7 @@ class ModuleTemplateFilterSample(ModuleBase):
155155
def double_filter_dec(cls, n):
156156
return n * 2
157157
```
158-
- ## `Module Request Events`
158+
### `Module Request Events`
159159
During application request handling, application router emits two events `start_up` and `shutdown` event.
160160
We can subscribe to those events in our modules.
161161
```python
@@ -185,7 +185,7 @@ These will be registered to the application router during `ModuleRequestEventsSa
185185
Also, the events can be `async` as in the case of `on_shutdown_func_2` and `on_startup_func_2`
186186

187187

188-
# `dependency injection`
188+
## `Dependency Injection`
189189
A module class can inject providers as well (e.g., for configuration purposes):
190190

191191
For example, from our sample project, the can inject `Config` to the `DogModule`
@@ -214,7 +214,7 @@ class DogsModule(ModuleBase):
214214
```
215215

216216

217-
# `Injector Module`
217+
## `Injector Module`
218218
Since `EllarInjector` is based on a python library [injector](https://injector.readthedocs.io/en/latest/index.html) both
219219
share similar `Module` features with few distinct features. As an added support, you can create or reuse modules from `injector` Modules.
220220

docs/overview/providers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
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+
23
So, in a way, providers are like services, repositories, factories etc., classes that can manage complex tasks.
34
This concept of class injection is known as [Dependency Injector](https://de.wikipedia.org/wiki/Dependency_Injection)
45

56
You can easily create a provider class by decorating that class with the `@injectable()` mark
7+
68
```python
79
from ellar.di import injectable, singleton_scope
810

@@ -88,7 +90,7 @@ class DogsController(ControllerBase):
8890
We have defined `DogsRepository` as a dependency to `DogsController` which means Ellar will resolve `DogsRepository` instance when creating `DogsController` instance.
8991
This was made possible by type definition on `dog_repo` parameter and with the type defined, Ellar knows the provider to look for.
9092

91-
!!info
93+
!!! info
9294
Every class dependencies should be defined in the class **constructor**, that way Ellar will resolve all the dependencies needed for an object instantiation.
9395

9496
## Provider registration

0 commit comments

Comments
 (0)