Sunday 1:30 p.m.–5 p.m.

Building a REST API Using Django & Django REST Framework

Kenny Yarboro

Audience level:

Novice

Description

Using a combination of Django and Django REST Framework, we will build a Restaurant Menu that can be managed via a REST API. Starting from the install of the Django REST Framework, we will build our way to a functional API that meets the needs of developers and end-users. You will walk away with an understanding of the basic concepts of REST APIs and a working sample project.

Abstract

This tutorial will cover how easy it can be to build your own REST API using Django and Django REST Framework. It is meant to be a course for people that have at least an introductory knowledge of Python, but are not familiar or comfortable with the Django world. The tutorial would start with a quick walkthrough of installing the relevant Django REST Framework version. From there, we will actually start coding a REST API for a simple Restaurant Menu application. This will include covering the necessary building blocks that are required. In building our Restaurant Menu application, we will control API access levels through Django Users and Groups. We will also go over the benefits of the Admin interface and the Browsable API interface. Once our base API is ready, we will start looking at advanced use cases. Based on time and attendee interest, we may be able to cover additional topics along the way or at the end. Those additional topics could be advanced API functionalities or coverage of general questions.

Section I - 1 hour

Quick Introductions

  • REST Architecture Overview
  • Django
  • Comparison of Django to the MVC Approach
  • Django REST Framework

Necessary Installs

  • Using virtualenv
  • Using pip
  • Install Django
  • Install Django REST Framework

Create Django Project

  • Run startproject
  • Cover Files Created & Their Purposes
  • Run Django Server
  • How to Add Content to the Application

Learn Basic Concepts While Building the Restaurant Menu Application

  • Adding the Model Code
  • Adding the Template Code
  • Adding the View Code
  • Updating the URLs Code
  • Modifying the Settings File

Building the Model in the Database

  • Building the Database Table for the Model
  • Insert a New Object into the Database
  • Get the ID from a New Object
  • Query the Database for Existing Objects

Viewing the Menu Page

  • Quick Look at the Restaurant Menu List WebPage

Section 2 - 1 hour

Enabling the Browsable API

  • Updating the Settings File
  • Modifying the URLs Code
  • Using the Browsable API
  • Explanation of Use Cases for the Browsable API

Setting Up the Admin Interface

  • Updating Admin Code
  • Viewing the Admin Interface

Determining Users & Groups

  • Discuss Difference Between Managers, Chefs, Others
  • Create Some Groups
  • Create Some Users

Limiting API Access Based on User Permissions

  • Discussion of HTTP Response Codes
  • Allow Managers to Set Prices & Manage Menu Items
  • Allow Chefs to Manage Menu Items
  • Allow Others ONLY to Get Menu List

Input Validation

  • Reasons to Validate Input
  • When to Use an Existing Validator
  • When to Use a Custom Validator
  • Responding to Invalid Input
  • Add Input Validation Logic

Section 3 - 30 minutes

Value of Debug Mode

  • Using the Debug Mode for Development
  • Understanding the Debug Information

Moving into Production

  • Determining When the API is Ready for Production
  • Why to Turn Off Debug Mode
  • Move API into Production
  • Explore the Results

Section 4 - 30 minutes

  • General Q&A
  • Freeform Activities Based on Audience Preferences