@@ -29,12 +29,14 @@ pip install ellar
29
29
## Create a project
30
30
To create an ellar project, you need to have a ` pyproject.toml ` available on your root directory.
31
31
This is necessary for ellar to store some ` metadata ` about your project.
32
+
32
33
### Step 1
33
34
For Pip Users, you need to create ` pyproject.toml ` file
34
35
``` shell
35
36
touch pyproject.toml
36
37
```
37
38
If you are using ` Poetry ` , you are ready to go
39
+
38
40
### Step 2
39
41
Run the ellar create project cli command,
40
42
``` shell
@@ -51,6 +53,7 @@ ellar runserver --reload
51
53
Now go to [ http://127.0.0.1:8000 ] ( http://127.0.0.1:8000 )
52
54
![ Swagger UI] ( img/ellar_framework.png )
53
55
56
+
54
57
## Create a project module
55
58
A project module is a project app defining a group of controllers or services including templates and static files.
56
59
So, now we have a project created, lets add an app to the project.
@@ -59,7 +62,7 @@ ellar create-module car
59
62
```
60
63
61
64
## Add Schema
62
- In ` car. schema.py ` , lets add some serializer for car input and output data
65
+ In ` car/ schema.py ` , lets add some serializer for car input and output data
63
66
``` python
64
67
from ellar.serializer import Serializer
65
68
@@ -74,7 +77,7 @@ class RetrieveCarSerializer(CarSerializer):
74
77
```
75
78
76
79
## Add Services
77
- In ` car. services.py ` , lets create a dummy repository ` CarDummyDB ` to manage our car data.
80
+ In ` car/ services.py ` , lets create a dummy repository ` CarDummyDB ` to manage our car data.
78
81
``` python
79
82
import typing as t
80
83
import uuid
@@ -127,7 +130,7 @@ class CarDummyDB:
127
130
return self ._data.pop(idx)
128
131
```
129
132
## Add Controller
130
- In ` car. controllers.py ` , lets create ` CarController `
133
+ In ` car/ controllers.py ` , lets create ` CarController `
131
134
132
135
``` python
133
136
import typing as t
@@ -175,7 +178,7 @@ class CarController(ControllerBase):
175
178
176
179
```
177
180
## Register Service and Controller
178
- In ` car. module.py ` , lets register ` CarController ` and ` CarDummyDB `
181
+ In ` car/ module.py ` , lets register ` CarController ` and ` CarDummyDB `
179
182
180
183
``` python
181
184
from ellar.common import Module
@@ -198,9 +201,27 @@ class CarModule(ModuleBase):
198
201
pass
199
202
```
200
203
204
+ ## Registering Module
205
+ Ellar is not aware of ` CarModule ` yet, so we need to add it to the ` modules ` list of ` ApplicationModule ` at the ` carsite/root_module.py ` .
206
+ ``` python
207
+ from ellar.common import Module, exception_handler
208
+ from ellar.core import ModuleBase
209
+ from ellar.core.connection import Request
210
+ from ellar.core.response import JSONResponse, Response
201
211
202
- ## Enabling OpenAPI
203
- To start up openapi, we need to go back to project folder in the ` carsite.server.py `
212
+ from ellar.samples.modules import HomeModule
213
+ from .apps.car.module import CarModule
214
+
215
+
216
+ @Module (modules = [HomeModule, CarModule])
217
+ class ApplicationModule (ModuleBase ):
218
+ @exception_handler (404 )
219
+ def exception_404_handler (cls , request : Request, exc : Exception ) -> Response:
220
+ return JSONResponse(dict (detail = " Resource not found." ))
221
+
222
+ ```
223
+ ## Enabling OpenAPI Docs
224
+ To start up openapi, we need to go back to project folder in the ` server.py `
204
225
then add the following below.
205
226
``` python
206
227
import os
0 commit comments