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
