The tool is able to generate APIs
using Django & DRF stack with a minimum effort. For newcomers, Django is a leading backend framework used to code from simple websites and APIs to complex eCommerce solutions.
Docker
π Step 1 - Download the code from the GH repository (using
GIT
)
$ git clone https://github.com/app-generator/devtool-django-api-generator.git
$ cd devtool-django-api-generator
π Step 2 - Start the APP in
Docker
$ docker-compose up --build
Visit http://localhost:5085
in your browser. By default a simple Books Model is used as sample.
http://localhost:5085/api/books
API-View
page
π Step #1 - Define models in
apps/models.py
By default, the project comes with a simple Books
model:
class Book(models.Model):
name = models.CharField(max_length=100)
π Step #2 -
Register the model
incore/settings.py
(API_GENERATOR section)
API_GENERATOR = {
'books': "Book", # <-- Books model provided as sample
}
π Step #3 -
Migrate Database
$ python manage.py makemigrations
$ python manage.py migrate
π Step #4 -
Generate API
$ python manage.py generate-api
Note
: if you define a model that wasn't migrated to db, you will see an error that say names of not migrated models and codes will not generate.
π Step #5 -
Use the API
POST
request to /api/books/
GET
request to /api/books/2/
GET
request to /api/books/
PUT
request to /api/books/2/
DELETE
request to /api/books/2/
π Step #6 - API Authentication
There are 2 models of authentication that you can use.
Token Based Authentication: send post request to
/login/jwt/
with username and password in body. Api will return a token.
POST /login/jwt/ {
"username": "sth",
"password": "sth"
}
The token should be used in all mutating requests (Create, Update, Delete)
{
"Authorization": "token {your token}"
}
Example:
{
"Authorization": "token b36705e1078b4b67d4dc4f1388a1aee4a754d4cd"
}
Basic Authentication
For users authenticated in the app.
Django API Generator - Developer tool provided by AppSeed