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: docs/index.md
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -12,19 +12,20 @@
12
12
13
13
---
14
14
## Introduction
15
-
Ellar is a lightweight ASGI framework for building efficient and scalable server-side python application.
15
+
Ellar is a lightweight ASGI framework for building efficient and scalable server-side python applications.
16
16
It supports both OOP (Object-Oriented Programming) and FP (Functional Programming)
17
17
18
-
Ellar is built around [Starlette](https://www.starlette.io/)(ASGI toolkit) which processes all the HTTP request and background tasks. Although, there is a high level
18
+
19
+
Ellar is built around [Starlette (ASGI toolkit)](https://www.starlette.io/) which processes all the HTTP requests and background tasks. Although, there is a high level
19
20
of abstraction, some concepts of Starlette are still supported.
20
21
21
22
## Inspiration
22
-
Ellar was heavily inspired by [NestJS](https://docs.nestjs.com/) in its simplicity in usage while managing complex project structures and application.
23
+
Ellar was heavily inspired by [NestJS](https://docs.nestjs.com/) in its simplicity in usage while managing complex project structures and applications.
23
24
It also adopted some concepts of [FastAPI](https://fastapi.tiangolo.com/) in handling request parameters and data serialization with pydantic.
24
-
With that said, the aim of Ellar focuses on high level of abstraction of framework APIs, project structures, architectures and speed of handling requests.
25
+
With that said, the aim of Ellar focuses on a high level of abstraction of framework APIs, project structures, architectures, and speed of handling requests.
25
26
26
27
## Installation
27
-
To get started, you need to scaffold a project using [Ellar-CLI](https://eadwincode.github.io/ellar-cli/) toolkit. This is recommended for first-time user.
28
+
To get started, you need to scaffold a project using [Ellar-CLI](https://eadwincode.github.io/ellar-cli/) toolkit. This is recommended for a first-time user.
28
29
The scaffolded project is more like a guide to project setup.
Copy file name to clipboardExpand all lines: docs/overview/controllers.md
+49-45Lines changed: 49 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
2
-
The Controller is responsible for handling incoming requests and returning responses to client.
3
-
The purpose of a controller is to receive specific requests for an application and`ApplicationRouter` decides which controller should handle an incoming request.
2
+
The Controller is responsible for handling incoming requests and returning responses to the client.
3
+
The purpose of a controller is to receive specific requests for an application `ApplicationRouter`.`ApplicationRouter`on the other hand, decides which `controller` should handle an incoming request.
Controllers can also be seen as a router which has many routes registered in it.
7
+
Controllers can be said to be a router with many routes registered in them.
8
8
9
-
### Creating a Controller
9
+
### **Creating a Controller**
10
10
To create a controller, we use classes and decorators. The `Controller` decorator associates classes with a required
11
11
`metadata` needed for Ellar to create a routing table
12
12
@@ -19,14 +19,11 @@ class UsersController(ControllerBase):
19
19
"""We have created a controller for Users"""
20
20
```
21
21
22
-
## Routing
23
-
In this section, we are going to highlight the important features of the `@Controller()`, a `class decorator`
24
-
for defining a controller. By default, `@Controller()` will create a path prefix `/dogs` gotten from class name in `Dogs`Controller
25
-
that will be used to group related routes and minimize duplicate route definition and code repetition.
26
-
27
-
For example, we may choose to group a set of routes that manage interactions with a customer entity under the route `/users`.
28
-
In that case, we could specify the path prefix `/users` in the `@Controller()` decorator so that we don't have to repeat that portion of the path for each route in the file.
22
+
## **Routing**
23
+
In this section, we are going to highlight key features of the `@Controller()`, a `class decorator`
24
+
for defining a controller. By default, `@Controller()` will create a path prefix `/dogs` gotten from the class name in `Dogs`Controller. This will be used to group related routes and minimize duplicate route definitions.
29
25
26
+
For example, we may choose to group a set of routes that manage interactions with a customer entity under the route `/users`. In that case, we could specify the path prefix `/users` in the `@Controller()` decorator so we don't have to repeat that portion of the path for each route in the controller.
30
27
31
28
```python
32
29
# project_name/apps/dogs/controllers.py
@@ -48,35 +45,36 @@ class DogsController(ControllerBase):
48
45
!!! hint
49
46
Class Decorators name are capitalized while function/method decorator name are in lower case
50
47
51
-
The `@get()` HTTP method decorator before the `get_all(self)` method marks `get_all(self)` as HTTP request handler for
52
-
a specific endpoint matching HTTP Request of `GET` and the route path. What is the route path of `get_all(self)`? The route
53
-
path is determined by concatenating the controller `path prefix` and path specified in the HTTP method function decorator `@get()`.
54
-
Since we've declared a prefix for every route `(dogs)`, and haven't added any path information in the decorator(`default='/'`),
55
-
Ellar will map `GET /dogs/` requests to this handler
48
+
The `@get()` HTTP method decorator before the `get_all(self)` method marks `get_all(self)` as the HTTP request handler that will handle a specific endpoint matching the route path and HTTP method of `GET`.
49
+
50
+
But what then is the route path of `get_all(self)`? The route path is determined by concatenating the controller `path prefix` and the path specified in the HTTP method function decorator `@get()`.
51
+
52
+
For example, we've declared a prefix for every route `(dogs)`, and haven't added any path information in the decorator, which means the path will default to `/`. In that case,
53
+
Ellar will map `GET /dogs/` requests to the `get_all(self)` handler.
56
54
57
-
For example, a path prefix of `/users` combined with the decorator `@get('/profile')` would produce a route mapping for requests like
55
+
Another example to help make things clear, a path prefix of `/users` combined with the decorator `@get('/profile')` would produce a route mapping for requests like
58
56
`GET /users/profile`.
59
57
60
58
61
-
### Overview of HTTP function decorator parameters:
59
+
### **Overview of HTTP function decorator parameters:**
`CreateDogSerializer`, a pydantic type, so fields(`name`, `age`, `breed`) validations according to defined types and
253
-
specifications is supported out of the box.
251
+
`CreateDogSerializer` is a pydantic type. These means `name`, `age` and `breed` fields are type validated out of the box.
252
+
253
+
It's important to note the way we used `CreateDogSerializer` as a type annotation of the `payload` parameter in the `create` route handler method.
254
+
Ellar will compute values for all the route handler parameters and validates them based on the annotated types before executing the handler.
254
255
255
-
It's important to note the way we used `CreateDogSerializer` as a type annotation to `payload` parameter in `create` method.
256
-
During request Ellar computes the route handler signatures and validates them to the annotated types before executing the handler.
256
+
!!! info
257
+
if a parameter is not annotated, it will be assumed as a `string` type
257
258
258
259

259
260
@@ -295,12 +296,15 @@ class DogsController(ControllerBase):
295
296
returnf'This action returns all dogs at limit={query.limit}, offset={query.offset}'
296
297
297
298
```
298
-
## Linking Controller
299
+
## **Linking Controller**
300
+
301
+
In the previous page, we already wired our `dogs` module (`DogsModule`) to `ApplicationModule` in `project_name/root_module` but this time we shall be adding things to the `DogsModule`. To keep things more simple, organized, and modular.
302
+
303
+
Let's register `DogsController` to `DogsModule`.
304
+
`@Module()` takes `controllers` as a parameter which is an array of the `ControllerBase` type.
299
305
300
-
In the previous page, we already wired our `dogs` module (`DogsModule`) to `ApplicationModule` in `project_name/root_module`
301
-
So, lets link `DogsController` to `DogsModule`.
306
+
In the `dogs` module,
302
307
303
-
It is good to note that controllers always belong to a module, which is why we include the `controllers` array within the @Module() decorator.
0 commit comments