@@ -49,9 +49,12 @@ Then add "easy" to your django INSTALLED_APPS:
4949]
5050```
5151
52-
53- Get your admin api up and running:
52+ ### Usage
53+ #### Get all your Django app CRUD APIs up and running
54+ In your Django project next to urls.py create new apis.py file:
5455```
56+ from easy.main import EasyAPI
57+
5558api_admin_v1 = EasyAPI(
5659 urls_namespace="admin_api",
5760 version="v1.0.0",
@@ -60,16 +63,58 @@ api_admin_v1 = EasyAPI(
6063# Automatic Admin API generation
6164api_admin_v1.auto_create_admin_controllers()
6265```
66+ Now go to urls.py and add the following:
67+ ```
68+ from django.urls import path
69+ from .apis import apis
70+
71+ urlpatterns = [
72+ path("admin/", admin.site.urls),
73+ path("api_admin/v1/", apis.urls), # <---------- !
74+ ]
75+ ```
76+ #### Interactive API docs
77+ Now go to http://127.0.0.1:8000/api_admin/v1/docs
78+
79+ You will see the automatic interactive API documentation (provided by Swagger UI).
80+ ![ Auto generated APIs List] ( https://github.com/freemindcore/django-api-framework/blob/fae8209a8d08c55daf75ac3a4619fe62b8ef3af6/docs/images/admin_apis_list.png )
6381
64- Please check tests/demo_app for more.
82+ #### Adding CRUD APIs to a specific API Controller
83+
84+ By inheriting CrudAPIController class, CRUD APIs will be added to your API controller.
85+ Configuration is available via Meta class:
86+ - ` model_exclude ` : fields to be excluded in Schema
87+ - ` model_fields ` : fields to be included in Schema, default to ` "__all__" `
88+ - ` model_join ` : prefetch and retrieve all m2m fields, default to False
89+ - ` model_recursive ` : recursively retrieve FK/OneToOne fields, default to False
90+ - ` sensitive_fields ` : fields to be ignored
91+
92+
93+ Example:
94+ ```
95+ @api_controller("even_api", permissions=[AdminSitePermission])
96+ class EventAPIController(CrudAPIController):
97+ def __init__(self, service: EventService):
98+ super().__init__(service)
99+
100+ class Meta:
101+ model = Event # django model
102+ generate_crud = True # whether to create crud api, default to True
103+ model_fields = ["field_1", "field_2",] # if not configured default to "__all__"
104+ model_join = True
105+ model_recursive = True
106+ sensitive_fields = ["password", "sensitive_info"]
107+
108+ ```
109+ Please check tests/demo_app for more examples.
65110
66111
67112### Boilerplate Django project
68- A boilerplate Django project for quickly getting started:
113+ A boilerplate Django project for quickly getting started, production ready easy-apis wiht 100% test coverage ready :
69114https://github.com/freemindcore/django-easy-api
70115
71- ![ Auto generated APIs List] ( https://github.com/freemindcore/django-api-framework/blob/fae8209a8d08c55daf75ac3a4619fe62b8ef3af6/docs/images/admin_apis_list.png )
72116![ Auto generated APIs - Users] ( https://github.com/freemindcore/django-api-framework/blob/9aa26e92b6fd79f4d9db422ec450fe62d4cd97b9/docs/images/user_admin_api.png )
73117![ Auto generated APIs - Schema] ( https://github.com/freemindcore/django-api-framework/blob/9aa26e92b6fd79f4d9db422ec450fe62d4cd97b9/docs/images/auto_api_demo_2.png )
74118
75- _ Note: this project is still in early stage, comments and advices are highly appreciated._
119+ ### Thanks to your help
120+ ** _ If you find this project useful, please give your stars to support this open-source project. :) Thank you !_ **
0 commit comments