An API endpoint is a network-accessible interface location that receives requests and returns API responses. In Django, an endpoint is a view: it inspects the HTTP method and performs the requested action. URL paths identify the operation and may include arguments such as an object's ID. section 11.1.2 section 11.2.2
A typical API exposes separate endpoints for listing objects and fetching one object. A single-object endpoint can connect a path value to a view argument, retrieve the matching database record, and serialize it for the response. Larger endpoint groups can add filtering and CRUD operations. section 11.2.2
A practical endpoint usually combines these pieces:
- A route such as /venue/{venue_id}/ identifies the operation and captures an argument. section 11.2.2
- A view function receives the request and captured value, then retrieves the object. section 11.1.2 section 11.2.2
- A serializer controls the returned representation, including computed fields such as a readable slug and URL. section 11.2.2
- A versioned URL lets breaking changes coexist with older endpoint versions while consumers migrate. section 11.1.2
Fetching a venue
GET /api/v1/bands/venue/1/ can return a venue representation containing id, name, description, slug, and URL. The view receives venue_id=1, retrieves the matching Venue, and Ninja serializes the result.
Listing 11.7 API endpoint for fetching a Venue object
# RiffMates/bands/api.py
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils.text import slugify
from ninja import Router, ModelSchema
from bands.models import Venue
router = Router() #1
class VenueOut(ModelSchema):
slug: str #2
url: str
class Meta:
model = Venue
fields = ["id", "name", "description"] #3
@staticmethod
def resolve_slug(obj): #4
slug = slugify(obj.name) + "-" + str(obj.id)
return slug
@staticmethod
def resolve_url(obj): #5
url = reverse("api-1.0:fetch_venue", args=[obj.id, ])
return url
@router.get("/venue/{venue_id}/",
response=VenueOut,
url_name="fetch_venue") #6
def fetch_venue(request, venue_id):
venue = get_object_or_404(Venue, id=venue_id)
return venue
Inspect the complete Django Ninja endpoint, including its route, response schema, computed fields, named URL, and database lookup. section 11.2.2

























