Skip to content

Commit 7cfa924

Browse files
committed
update README.md
1 parent 025dbac commit 7cfa924

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,79 @@
3333
pip install ellar
3434
```
3535

36+
## Usage
37+
38+
Create a file `controller.py`:
39+
40+
```Python
41+
from ellar.common import ModuleRouter, Controller, get
42+
43+
router = ModuleRouter('', tag='Math')
44+
45+
46+
@router.get("/add")
47+
def add(request, a: int, b: int):
48+
return {"result": a + b}
49+
50+
51+
@Controller("", tag='Math')
52+
class MathAPI:
53+
54+
@get('/subtract', )
55+
def subtract(self, a: int, b: int):
56+
"""Subtracts a from b"""
57+
return {"result": a - b}
58+
59+
@get('/divide', )
60+
def divide(self, a: int, b: int):
61+
"""Divides a by b"""
62+
return {"result": a / b}
63+
64+
@get('/multiple', )
65+
def multiple(self, a: int, b: int):
66+
"""Multiples a with b"""
67+
return {"result": a * b}
68+
69+
```
70+
71+
Create another file `server.py`:
72+
73+
```Python
74+
from ellar.core import AppFactory
75+
from ellar.openapi.builder import OpenAPIDocumentBuilder
76+
from ellar.openapi.module import OpenAPIDocumentModule
77+
from .controller import router, MathAPI
78+
79+
80+
app = AppFactory.create_app(routers=(router, ), controllers=(MathAPI, ))
81+
82+
document_builder = OpenAPIDocumentBuilder()
83+
document_builder.set_title('Your Title')\
84+
.set_version('1.0.2')\
85+
.set_contact(name='Eadwin', url='https://www.yahoo.com', email='[email protected]')\
86+
.set_license('MIT Licence', url='https://www.google.com')
87+
88+
document = document_builder.build_document(app)
89+
module = app.install_module(OpenAPIDocumentModule, document=document)
90+
module.setup_swagger_doc()
91+
```
92+
93+
### Interactive API docs
94+
95+
Now go to <a href="http://localhost:8000/docs/" target="_blank">http://localhost:8000/docs/</a>
96+
97+
You will see the automatic interactive API documentation (provided by <a href="https://github.com/swagger-api/swagger-ui" target="_blank">Swagger UI</a>):
98+
99+
![Swagger UI](docs/img/ellar_demo.gif)
100+
36101
## Status
37102
Project is still in development
103+
- Remaining testing modules:
104+
- common
105+
- configuration
106+
- guard
107+
- openapi
108+
- Project CLI scaffolding
109+
- Database Plugin with [Encode/ORM](https://github.com/encode/orm)
110+
- Caching
111+
- API Throttling

ellar/common/decorators/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def Controller(
8282
] = None,
8383
include_in_schema: bool = True,
8484
) -> t.Union[t.Type[ControllerBase], t.Callable[..., t.Any], t.Any]:
85-
_prefix: t.Optional[t.Any] = prefix or NOT_SET
85+
_prefix: t.Optional[t.Any] = prefix if prefix is not None else NOT_SET
8686
if prefix and isinstance(prefix, type):
8787
_prefix = NOT_SET
8888

0 commit comments

Comments
 (0)