DELETE method- Python requests
Last Updated :
26 Feb, 2020
Improve
Requests library is one of the important aspects of Python for making HTTP requests to a specified URL. This article revolves around how one can make DELETE request to a specified URL using requests.delete() method. Before checking out the DELETE method, let's figure out what a Http DELETE request is -
Python3 1==
save this file as request.py and through terminal run,
DELETE Http Method
DELETE is a request method supported by HTTP used by the World Wide Web. The DELETE method deletes the specified resource. As with a PUT request, you need to specify a particular resource for this operation. A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity. An example URI looks like for delete operationhttp://www.example.com/articles/12345
How to make DELETE request through Python Requests
Python's requests module provides in-built method called delete() for making a DELETE request to a specified URI. Syntax -requests.delete(url, params={key: value}, args)Example - Let's try making a request to httpbin's APIs for example purposes.
import requests
# Making a DELETE request
r = requests.delete('https://httpbin.org / delete', data ={'key':'value'})
# check status code for response received
# success code - 200
print(r)
# print content of request
print(r.json())
python request.pyOutput -
