Building web APIs with django

Building web APIs with django

Hey there, I'd like to introduce you to making web APIs with the popular python web framework, Django.

You've probably heard that the best way to learn is by doing. So in this walkthrough, we'll be building a RESTful API with Django and the django rest framework. The project will be an event scheduler application, sort of like a mini version of Eventbrite or meetup.com.

Key features will be users to create events and other registered users can mark attendance to the created events. We'll also explore how to review an event, putting in place checks to ensure only those members who attended the event can review any given event. Hopefully, by the end of the series, you too can apply some of the concepts here to build your own REST APIs with Django.

You'll find the project's code on github.

The walkthrough will be divided into three major parts for ease of readability so as not to boggle you down with too many concepts at the same time.

  1. Introduction and project setup(You are here).
  2. User registration,authetication and authorization with djoser and JSON web tokens(JWTs).
  3. Events creation and attendance endpoints.

I'll try to follow a similar structure in each post. This will mainly involve:

  1. Model creation.
  2. Serializers, API views and modifying them to suit our needs.
  3. Creating permission classes for our endpoints.
  4. Writing automated unit tests for the endpoints.
  5. Demo with postman.

Project setup

For this project, we'll need to have python 3+ installed. You can find the necessary steps here. Next, we'll need to make virtual environments for installing project dependencies.

Install virtualenv

pip install virtualenv

Create a new virtualenv

virtualenv yourenvname -p python3.6

Activate virtual environment

source yourenvname/bin/activate Run this command within the directory the virtual environment was created in.

Once your virtual environment is activated, there's a number of dependencies we'll be needing for the project:

  1. Django and the Django rest framework pip install django djangorestframework
  2. Djoser: REST implementation of Django authentication system. The Djoser library provides a set of Django Rest Framework views and endpoints to handle basic actions such as registration, login, logout, password reset, and account activation. You could build out the features yourself but this has most of the features you may end up building. pip install djoser
  3. django-rest-framework-simplejwt: provides a JSON Web Token authentication backend for the Django REST Framework. pip install djangorestframework_simplejwt

Typically, if you have a lot of project dependencies in python, it's advisable to put them in a requirements.txt file and install them with one command. pip install -r requirements.txt

To kick off the new django project, run the following once you've activated the previously created virtual environment. django-admin startproject eventScheduler

Now to start with the first app that we'll be requiring for the next section:

cd eventScheduler
python manage.py startapp accounts

So far so good I hope. If you've followed the steps along, our app should now be having its structure as

./eventScheduler
├── accounts
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── eventScheduler
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   └── settings.cpython-35.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

Over the next few days, we'll go over the various ways of implementing RESTful APIs with Django, filling in the different sections Indindicated previously.

In case you have any questions, leave a comment below or contact me on twitter and I'll get back to you as soon as possible.

Thanks.

Sponsors

Some of the links below are affiliate links, which means I may earn a small commission — at no extra cost to you. I only recommend tools, products, and services I’ve personally used and found genuinely helpful in my work or learning journey. These sponsors quietly help keep the lights on around here — and I’m grateful for that. Please don’t buy anything you can’t afford or aren’t ready to put to use.

Scraper API

Scraper API

Scraper API is built for developers who need reliable, scalable web scraping without the headache of IP blocks or CAPTCHA walls. They handle IP rotation, CAPTCHA solving, and even headless browser emulation — so your scrapers look and behave like real users.

With over 20 million IPs, unlimited bandwidth, and built-in support for popular libraries like requests, BeautifulSoup, Scrapy, and Selenium, it works seamlessly across the Python ecosystem — and beyond. Whether you're using Node.js, Bash, PHP, or Ruby, integration is as simple as appending your target URL to their API endpoint.

If you're new to scraping, don’t worry — I’ve covered it extensively in the webscraping series, and it's all free.

Use this link + code lewis10 to get 10% off your first purchase. They’ve got a generous free plan — scale up only when you need to.

scraperapi

Digital Ocean

Digital Ocean

DigitalOcean makes it easy to launch, scale, and manage your cloud infrastructure — without the overwhelm.

Simple pricing. Powerful API. A clean UI that actually respects your time.

Use this link to get $200 in free credits for your first two months. Perfect for testing, launching, or scaling your next side project or startup.

Share to social media