Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Sneaky REST APIs With Django Ninja (Overview)

Many web projects have moved to the single-page application model. To use this model with Django, you build a project where Django is the back end accessed through a REST API. The Django Ninja library is a FastAPI-inspired tool kit for turning Django views into REST API endpoints with very little extra code. Along the way, you’ll be using curl, a command-line tool that allows you to grab the contents of a web page.

If you’d like to quickly build API endpoints and learn the ways of the Ninja, you’re in the right place.

In this course, you’ll learn about:

  • REST APIs
  • Django Ninja
  • URL arguments and query strings
  • Serialization through Schema and ModelSchema classes
  • CRUD operations
  • Authentication
  • Error management

To get the most out of this course, you’ll need to have prior experience with the Django framework. You don’t need to be an expert, but you do need to understand the basics of views, models, and URL routes. If you need a refresher on these topics, check out:

Download

Sample Code (.zip)

27.1 KB

Download

Course Slides (.pdf)

976.1 KB

00:00 Welcome to Sneaky REST APIs with Django Ninja. My name is Christopher, and I will be your guide. This course is all about the Django Ninja package, which is used for building REST interfaces in your Django project.

00:14 You’re going to learn about REST APIs, Django Ninja, URL arguments and query strings, serialization through Schema and ModelSchema classes, CRUD operations, authentication, and error management.

00:33 Django is a pretty big framework, and as such, this course doesn’t cover it. You’re going to need basic familiarity with some of the key concepts of Django, including models, views, and URLs.

00:45 I’ll occasionally be using the management shell, so you’ll need to know how to get into that. And I’m going to be using some sample data, so you’ll either need to know how to load fixtures from the sample code or use the Django admin to enter some of your own.

00:58 If you need to brush up on any of these concepts, you may want to read another tutorial or take another course first. Links below can point you at some possible material to get you started.

01:08 To demonstrate the REST interfaces I’ll be building, I’m going to be using a command-line tool called curl. If you haven’t used it before, it allows you to grab the contents of a web page, among many other things.

01:20 Most Unix-like operating systems come with it installed. For those that don’t, or if you’re using the versions of Windows that don’t come with it, you’ll need to grab it if you want to code along with me.

01:33 REST is short for representational state transfer, and it is a standard that isn’t a standard. It’s more of a coding pattern which is in very common use. It’s built on top of HTTP operations, like GET and POST and uses the HTTP request and response bodies for payloads.

01:53 Typically, your data is encoded in either JSON or XML inside of the payload. REST is the de facto way of doing single-page applications nowadays. You use something like Django for the server and then Vue or React or Angular or whatever else for the front end, with REST being the communication glue between the browser and the server.

02:19 Ninja is a library that helps you write REST interfaces on top of your Django views. It is heavily inspired by Fast API and uses decorators to change your view into a REST call.

02:31 Ninja includes a layer that handles the serialization and deserialization of your data, meaning you have less code to write. It also provides several different ways of doing authentication and has a solid exception-management mechanism.

02:46 REST isn’t meant to be too complicated, and Ninja gives you several ways of organizing your code—a flexibility that allows you to keep it simple for small projects, or have a bit more definition for your larger ones.

03:00 Next up, I’ll start you on your journey by giving an overview of REST. If you’re already comfortable with REST, GETs, POSTs, PUTs, DELETEs, and

03:10 JSON payloads, feel free to skip this. Lesson 3 is where I introduce Ninja.

Become a Member to join the conversation.