A tour through API Bakery features for Django
May 20th, 2021
In this article:
The goal of API Bakery is to make starting a new project insanely quick and easy. Here's an overview of the supported features and functionality that API Bakery can build for you when you start a new Django project.
Base project setup
API Bakery creates
manage.py, settings files, project's
wsgi.py so you can run Django from your favorite web server, such as gunicorn. This is also what a standard
createproject Django admin command would do.
A better settings setup
API Bakery goes further though, with an extensible settings setup. Instead of a single
settings.py file you get with a typical Django starter project, we use environment variables for configuration.
There's still a
settings/base.py file for parts of the configuration that don't change - such as installed Django apps (yours and third party), template paths and the like. However, most of the configuration that is likely to change between your local workstation, your coworkers, test servers and production servers, is pulled from environment.
This is a flexible approach popularized by Heroku and their 12-factor app setup, and is supported by Heroku, docker and kubernetes. It is also easy to use if deploying directly to a VM or VPS, for example with Linux systemd.
The environment variables can be set either in an
.env file located in the root of your project, or by setting them directly in the environment, or the combination. Variables set directly in the environment have greater preference than the ones from the
.env file, so you can mix and match.
Model, fields and admin support
Models generated through API Bakery support most field types with reasonable defaults and many of the most used options available via a few clicks. Whether it's a
ManyToMany relation or one of the many other field types, we've got you covered. File and image (with image format verification) fields are also supported and file uploads via API are handled automatically.
If you enable Django admin, your models can be automatically registered in the Django admin interface. It's easy to add specific fields to search for or list in the admin interface.
You can optionally enable authentication with either username+password or email+password combination. Generated auth models are easily extensible and we use allauth so you can add social auth or other functionality later if you want - no need to replace the entire auth system to add it.
Signup, login, logout and password recovery via API is fully supported.
API endpoints and Swagger support
API Bakery is using the awesome Django REST Framework for providing rich RESTful API endpoints. You can enable API for the standard CRUD (Create, List/Read, Update, Delete) operations on all the models you define, as well as permissions for accessing them. If you use auth and have included a foreign key to the user owning your model instances, you can restrict some operations to the instance owner.
Browsable API are enabled by default, so you can visit the API endpoints from your browser and use it while development and testing your project.
You can optionally enable Swagger (OpenAPI), which will generate the openapi schema as well as the swagger UI for inspecting and interacting with it.
Generated project contains an up to date
requirements.txt with pinned dependencies and the included
README.md file contains instructions on creating your Python virtual environment and installing dependencies with
Deploying to Heroku is supported as an option - if you enable it, we'll create a Procfile to run your Django server. If you prefer containers, enabling Docker support will set up a
Dockerfile you can use to containerize your project.
The little things
API Bakery does a bunch of little things that together make your experience easier and better. Generated project has a
README.md file describing steps to set the project up locally, so anyone can pick up the project and get started quickly. Test scaffolding is in place, with a couple of tests, so you can start writing tests for your own code quickly.
And we take great pains to ensure the code in every generated file is of high quality and maintainable. It should feel as if you yourself, or one of your coworkers, wrote that code. Only a hundred times faster and without errors - we run the tests ourselves before you ever download and open up the code.