Quick Start Part 1: First API
Install Django Ninja, create an API in locallibrary, write an endpoint, and open the interactive docs.
3 minute read
In three short pages you’ll build a small chat API for the chat rooms in your locallibrary: people can browse rooms, filter and paginate them, read a room’s messages, sign in, and post a message that shows up live in the chat page. Along the way you’ll see most of what makes Django Ninja pleasant to use: type hints that validate input, schemas generated from your models, interactive docs, auth, and routers.
This guide assumes you already know Django: projects, apps, models and migrations. It won’t explain those; it only shows the Django Ninja parts.
| Page | What you’ll do |
|---|---|
| 1. First API | Install, create an API, write an endpoint, open the interactive docs |
| 2. Models & Schemas | Save chat rooms and messages to the database, then full CRUD for the Room model, plus pagination and filtering |
| 3. Auth, Routers & Next Steps | Split the API into a router, require login, let users post messages to a room |
We assume that you have completed preps 01-06 (our fork of the MDN Django Tutorial through Part 8) and all four parts of our Channels tutorial. You have your locallibrary repository: a uv project with manage.py, pyproject.toml, and uv.lock at its root, the locallibrary_config project package, the catalog app, and the asynchronous chat app. Every command in this guide is run from that root folder.
The chat app works, but it forgets everything: a message exists only while it travels through Redis to the browsers in the room. An API that lists rooms and messages needs them in the database. So before the Django Ninja parts, page 2 adds Room and Message models to the chat app, saves every message to the database, and shows a room’s history when you open it.
This is a copy of the official Django Ninja Quick Start, changed to match the way we have worked in our fork of the MDN Django Tutorial and our Channels tutorial:
mysite, this copy says locallibrary_config, and the original’s events app is your chat app.Event model, and users register for events. This copy builds the same API for a Room model, and users post Messages to rooms. Each piece of the original has a counterpart here: EventFilter’s upcoming filter becomes RoomFilter’s recent filter, the 409 for an event that clashes with another becomes a 409 for a room name that’s taken, and the nested RegistrationOut schema becomes a nested MessageOut schema.Room and Message models, saves messages from the WebSocket consumer, and shows a room’s saved messages when you open it. The original has nothing like this, because it starts from an empty app.pip install becomes uv add, and every command is run with uv run python ….urls.py contents because it assumes a new, empty project. Here you only add lines, so you keep what you built for catalog and chat.This copy follows the Django Ninja documentation as of 2026-10-19 (Django Ninja 1.7.1), on Django 6.1, Channels 4.3, and Python 3.14. Once you finish, continue with our Django Ninja Tutorial.
The original Quick Start is Copyright (c) 2025 Vitaliy Kucheryaviy, and is used under its MIT license.
Install Django Ninja, create an API in locallibrary, write an endpoint, and open the interactive docs.
Save chat rooms and messages to the database, then build a CRUD API for rooms with pagination and filtering.
Move the endpoints into the chat app, require login for writes, and let signed-in users post messages to a room.