A decorator attaches additional behavior to a function. In a web API, it can also declare what the function represents: Django Ninja uses HTTP-method decorators to turn Django view functions into API endpoints, reducing repetitive endpoint setup. section 11.2 section 11.5
A decorated API endpoint
The @router.get("/") line decorates home and associates it with an HTTP GET route. When a request reaches that route, Ninja calls home(request), and the returned string becomes the response. section 11.2
Decorators can carry configuration as well as behavior. Ninja provides separate decorators for HTTP methods; their arguments can specify a route suffix, response schema, endpoint name, or authentication mechanism. The decorated routes are collected by a Router, registered on one NinjaAPI object, and exposed through api.urls in Django’s URL configuration. section 11.5
When reading or writing a decorated endpoint, check:
- Choose the decorator matching the HTTP method, such as GET, POST, PUT, PATCH, or DELETE. section 11.5
- Treat the decorator’s route arguments and the view function’s arguments as a pair: URL values and query parameters are declared through the endpoint definition. section 11.5
- Keep endpoint grouping and central API registration distinct: Routers collect routes, while NinjaAPI exposes them through Django URLs. section 11.5






