Django API generator over DRF
Project description
Django API Generator
The tool is able to generate APIs
using Django & DRF stack with a minimum effort.
Actively supported by AppSeed via
Discord
.
How to use it
Step #1 - Install the package via
PIP
$ pip install django-api-generator
// OR
$ pip install git+https://github.com/app-generator/django-api-generator.git
Step #2 Update Configuration, include the new APP
INSTALLED_APPS = [
'django_api_gen', # Django API GENERATOR # <-- NEW
'rest_framework', # Include DRF # <-- NEW
'rest_framework.authtoken', # Include DRF Auth # <-- NEW
]
Step #3 -
Register the model
incore/settings.py
(API_GENERATOR section)
API_GENERATOR = {
# pattern:
# API_SLUG -> Import_PATH
'books' : "app1.models.Book",
}
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
],
}
Step #4 -
Migrate DB
and create the tables used byDRF
$ python manage.py makemigrations
$ python manage.py migrate
Step #5 -
Generate API
$ python manage.py generate-api
The code is generated under the api
folder in the root of the project.
Step #6 - Update routing, include APIs
from django.contrib import admin
from django.urls import path, include # <-- NEW: 'include` directive added
urlpatterns = [
path("admin/", admin.site.urls),
path("api/" , include("api.urls")), # <-- NEW: API routing rules
]
Step #7 - Update routing, include
DRF
JWT authentication
from django.contrib import admin
from rest_framework.authtoken.views import obtain_auth_token # <-- NEW
urlpatterns = [
path("admin/", admin.site.urls),
path("api/" , include("api.urls")),
path('login/jwt/', view=obtain_auth_token), # <-- NEW
]
Step #8 -
Use API
If the managed model is Books, the API interface is /api/books/
and all CRUD methods are available.
Django API Generator - Open-source library provided by AppSeed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-api-generator-0.0.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 690910a0bf3644a7151b773ddeb01e9f58b8f7e4dcfd1e2cd2be27d5ce6d7c3a |
|
MD5 | 9c554b14f9e4bb4380a03dbcbefb3576 |
|
BLAKE2b-256 | b7fd3a96b03f1b625f7dd5f1148de7dcfd865a15fb709f378b73facbbbdf1f27 |