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/api_controller/index.md
+9-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,10 @@
2
2
3
3
APIController is a borrowed term from the C# ASP.NET environment which is an MVC framework. Although Django is not an MVC framework, we can still mimic the concept generally just like any other programming concept.
4
4
5
-
Django-Ninja-Extra APIController is modelled after C# ASP.NET ApiController, giving all OOP sense in creating your controller models and adapting recent software design patterns in your Django project.
5
+
Django-Ninja-Extra APIController is modelled after C# ASP.NET ApiController, giving all OOP sense in creating your controller models and adapting recent software design patterns in your Django project.
6
6
7
7
### Why APIController in Django.
8
+
8
9
I come from a background where we model anything in class based object, and I have worked with many API tools out there in python: DRF, FastAPI, Flask-Restful. It is either function based or class tailored to function based.
9
10
Don't get me wrong, there are still great libraries. In fact, some features of Django-Ninja-Extra came from DRF. So I am a big fan. I needed more.
10
11
@@ -14,18 +15,20 @@ So I designed APIController to extend Django-Ninja to class-based and have somet
14
15
15
16
So if you enjoy class-based controls for building API, welcome aboard.
16
17
17
-
18
18
## ControllerBase
19
+
19
20
```python
20
21
classControllerBase(ABC):
21
22
...
22
23
```
24
+
23
25
APIController decorates any class with `ControllerBase` if its not inheriting from it.
24
26
25
27
!!!info
26
-
Inheriting from ControllerBase class gives you more IDE intellisense support.
28
+
Inheriting from ControllerBase class gives you more IDE intellisense support.
27
29
28
30
## Quick Example
31
+
29
32
Let's create an APIController to manage Django user model
30
33
31
34
```python
@@ -66,9 +69,9 @@ class UsersController(ControllerBase):
66
69
user =self.get_object_or_exception(self.user_model, id=user_id)
0 commit comments