python requests library api

Python Requests Library API

Python is a programming language that provides a wide range of libraries to help developers solve problems easily. One of the most popular libraries in Python for HTTP requests is the Requests library. It is a simple and user-friendly library that allows developers to send HTTP/1.1 requests extremely easily.

Requests library provides a powerful API for making HTTP requests. There are several ways to make requests with the Requests library. Some of the most commonly used methods are GET, POST, PUT, DELETE, and HEAD.

GET Method

The GET method is used to retrieve information from the specified URL. It is the most common method used in HTTP requests.


import requests 

url = 'https://api.example.com/get_data'

response = requests.get(url)

print(response.content)
    

POST Method

The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.


import requests 

url = 'https://api.example.com/post_data'

data = {'key1':'value1', 'key2':'value2'}

response = requests.post(url, data=data)

print(response.content)
    

PUT Method

The PUT method is used to update an existing resource with new data.


import requests 

url = 'https://api.example.com/put_data'

data = {'key1':'new_value1', 'key2':'new_value2'}

response = requests.put(url, data=data)

print(response.content)
    

DELETE Method

The DELETE method is used to delete a resource identified by the URL.


import requests 

url = 'https://api.example.com/delete_data'

response = requests.delete(url)

print(response.content)