How to Create a Simple Recipe API with Django and Python

How to Create a Simple Recipe API with Django and Python

Django gives us the ability to create API’s at a minimum time while preserving the versatility of Python. We will be able to create a simple recipe app that will be ready to use via POSTMAN or any other URL call.

Having an API that performs CRUD seamlessly across the platform is very important. Having a single source of data for various platforms like apps and website is a must at this age and day.

Django gives us the ability to create API’s at a minimum time while preserving the versatility of Python. We can create API’s with a fully functional dashboard within minutes. On top of that, It has a GUI with ADMIN login such as authentication adding users are already inbuilt.

In this article, we will be able to create a simple recipe app that will be ready to use via POSTMAN or any other URL call.

Disclaimer for Details and Actual Documentation. **[DJANGO DOCS**](https://docs.djangoproject.com/en/3.1/topics/)

Creating the Environment

Things we are gonna need to create the API:

  1. Python 3+
  2. Git Bash (or Powershell)
  3. Visual Studio Code or any text editor you like

But first, we need to create an isolated virtual environment.

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them. This is one of the most important tools that most Python developers use.

The following Commands are used to set up and activate.

Create the directory for this environment in any of your preferred drive.

mkdir /C/”your project”

cd /C/”project”

Image for post

Now you are in the Project Directory. Time to set up a virtual environment.

If you are in Python 2 use, even tho it is not preferred.

python -m virtualenv djangoapi

Else if in Python 3, use.

python -m venv djangoapi

Now to activate the virtual environment.

In Windows

Source venv/scripts/activate
in Mac 
source bin/activate

You can see the packages installed inside the environment. You can check on that by using** pip freeze. **AS of now, you wouldn’t see any list of packages added.

Image for post

Next, we install all the dependencies we need. And then you should run pip freeze to see the changes.

pip install Django

pip install Djangorestapi

Once you have successfully installed all dependencies it should look like this.

Image for post

STARTING THE PROJECT

Once We have successfully installed Django, it's time to create our recipe project. Django has made our lives easier by giving a bunch of predefined commands. You can the Start project command to

django-admin.py startproject djangoapiproject

now hit ls to see the directory.

Image for post

Now our directory for the project has been created.

We can now transfer onto the Text Editor, my preference is Visual Studio Code.

Select your the designated folder in my case which is

C/Djangoapi/Djangoapiproject

Before we can migrate all our dependencies we need to first see whether all of them are listed in settings.py. In my case, rest_framework was to be added.

Image for post

Now that we have added the applications list, we can now migrate the dependencies.

winpty python manage.py migrate

You will see all of your admin dependencies being migrated into the manage.py

Image for post

Now from the manage.py file will become the focal point of our project.

To see the changes successfully installed.

python manage.py runserver

You can observe the live project in the following by going on to localhost:8000

Image for post

Now we are set up to create our very first own API.

python django api web-development developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Python Developers

Are you looking for experienced, reliable, and qualified Python developers? If yes, you have reached the right place. At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, our full-stack Python development services...

Hire Python Developers India

Looking to build robust, scalable, and dynamic responsive websites and applications in Python? At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, we constantly endeavor to give you exactly what you need. If you need to...

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

A Simple Guide to API Development Tools

APIs can be as simple as 1 endpoint for use by 100s of users or as complex as the AWS APIs with 1000s of endpoints and 100s of thousands of users. Building them can mean spending a couple of hours using a low-code platform or months of work using a multitude of tools. Hosting them can be as simple as using one platform that does everything we need or as complex as setting up and managing ingress control, security, caching, failover, metrics, scaling.