liveBook · Manning

Django Ninja docs

As explained in Django in Action

Django Ninja docs is an interactive API documentation interface that displays endpoints, schemas, requests, and responses and can execute calls.

Django Ninja docs is an interactive interface for exploring an API and trying its calls without manually constructing HTTP requests. Open it by adding docs to the API URL, such as http://localhost:8000/api/v1/docs; unlike many endpoints, the URL must not end with a slash. section 11.2.6

Use the interface to:

  • Play with API endpoints while developing a create-venue operation. section 11.2.6
  • Inspect and exercise calls that accept typed payloads, such as VenueIn. section 11.2.6
  • Treat the interface as a hands-on aid, while keeping unit tests for repeatable verification. section 11.2.6
Listing 11.13 A create endpoint for venues
# RiffMates/bands/api.py
...
from api_auth import api_key  #1
...
class VenueIn(ModelSchema):  #2
    class Meta:
        model = Venue
        fields = ["name", "description"]

...

@router.post("/venue/", response=VenueOut, auth=api_key)  #3
def create_venue(request, payload:VenueIn):  #4
    venue = Venue.objects.create(**payload.dict())  #5
    return venue

See a protected POST endpoint that accepts a VenueIn payload, creates a Venue, and returns VenueOut. section 11.2.6

How Django in Action covers it

How deep it goes
Explains the docs URL and practical use, but defers automated verification to unit tests.
Examples
Uses a local API docs URL and a protected venue-creation endpoint as concrete examples.
What it assumes
Assumes a reachable Ninja API and basic URL awareness, but removes the need to handcraft test requests.
What you can do after
Operate a Django Ninja API interactively without manually assembling an HTTP call.
How it connects
Connects API endpoints with schemas, HTTP requests, authentication, and unit testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.