Skip to content

HTTP Methods

Defining operations

An "Operation" can be one of the HTTP "methods":

  • GET
  • POST
  • PUT
  • ... and more

Django Ninja comes with a decorator for each operation:

def get_operation(request):
def post_operation(request):

def put_operation(request):

def delete_operation(request):

def patch_operation(request):

See the Operations parameters reference docs for information on what you can pass to any of these decorators.

Handling multiple methods

If you need to handle multiple methods with a single function for a given path, you can use the api_operation decorator:

@api.api_operation(["POST", "PATCH"], "/path")
def mixed(request):

This feature can also be used to implement other HTTP methods that don't have corresponding django-ninja methods, such as HEAD or OPTIONS.

@api.api_operation(["HEAD", "OPTIONS"], "/path")
def mixed(request):