Delete a resource
Removing a server-side resource through an HTTP API.
Requests · Function
Sends an HTTP DELETE request to a URL and returns the resulting Response object. Optional keyword arguments use the same request configuration supported by requests.request.
Call this convenience function with the target URL and any optional keyword arguments accepted by requests.request. It creates and sends a DELETE request, then returns the resulting Response object, which exposes the status code, headers, body, and other response details.
requests.delete(url, **kwargs)| Name | Type | Description |
|---|---|---|
url | _t.UriType | URL for the new Request object. |
**kwargs | Unpack[_t.RequestKwargs] | Optional arguments accepted by requests.request. |
Response object
import requests
response = requests.delete(
"https://httpbin.org/delete",
headers={"Accept": "application/json"},
)
response.raise_for_status()
print(response.status_code)Sends a DELETE request and checks that the server returned a successful HTTP status.
Removing a server-side resource through an HTTP API.
Passing request options such as headers, authentication, or timeouts through the common request interface.
Inspecting the returned HTTP status and response metadata after deletion.
requests.delete is a convenience function for sending an HTTP DELETE request. Its signature accepts a URL plus optional keyword arguments, and it returns a Response object.
Follow-up: How would you inspect whether the operation succeeded? Check response.status_code or call response.raise_for_status() before processing the response.
The required url identifies the new Request object. The optional **kwargs provide the request configuration supported by requests.request.
Follow-up: Why is this useful? It gives the convenience method the same configuration surface as the general request API while fixing the HTTP method to DELETE.
The function sends the DELETE method to the supplied URL and returns the server's Response object. The response can then be used to inspect status and other HTTP response data.
Follow-up: What if the server returns no content? Use the response metadata, such as status_code, rather than assuming a response body exists.
requests.requestrequests.getrequests.optionsrequests.headrequests.postrequests.putrequests.patchrequests.Session.delete