DELETE is the HTTP method used by a REST-style API to request removal of a resource. In the CRUD shorthand, it supplies the delete verb: URLs identify the API’s nouns, while HTTP methods say what action to take on them. section 11.1.1 section 11.5
A delete request normally targets one object by putting its ID in the URL, such as /venue/{venue_id}/. The server looks up that object, removes it, and returns a response. If the ID is absent, the lookup produces a 404 response rather than quietly deleting nothing. section 11.2.7
Deleting a venue with Django Ninja
Register a route with @router.delete("/venue/{venue_id}/", auth=api_key). The handler uses get_object_or_404() to find the Venue, calls venue.delete(), then returns {"success": True}. The decorator defines the HTTP-facing DELETE endpoint; the model method performs the database removal. section 11.2.7 section 4.5
Listing 11.15 A delete endpoint for venues
# RiffMates/bands/api.py
...
@router.delete("/venue/{venue_id}/", auth=api_key)
def delete_venue(request, venue_id):
venue = get_object_or_404(Venue, id=venue_id)
venue.delete()
return {"success": True}
This endpoint shows the full request path: URL ID, object lookup, database deletion, and a small success response. section 11.2.7
Choose DELETE according to the API’s purpose:
- Provide it when clients such as mobile front ends need the full range of CRUD operations. section 11.2.7
- Omit it from a read-only API, such as one intended only to expose data like an RSS feed. section 11.2.7
- Return either the deleted object or success/failure metadata; returning the object can support undo or re-save behavior. section 11.2.7
Do not confuse an API DELETE request with Django’s .delete() method. DELETE is the HTTP instruction sent to an endpoint; calling .delete() on a retrieved model instance removes its corresponding database object. The Python instance can still exist in memory afterward, so inspect the database with a new query when verifying the result. section 4.5 section 4.12







