GET and POST requests
Introduction
In this article, we'll talk about the Python implementations of the GET and POST HTTP (Hypertext Transfer Protocol) request methods.
What is HTTP?
A group of protocols known as HTTP are used to facilitate client-server communication. It functions as a client-server request-response protocol.
The client could be a web browser, and the server could be an application running on the computer that is hosting the website.
To request a response from the server, there are mainly two methods:
- GET: To get the response from the server.
- POST: To submit the data to the server.
The most simplest of all listed libraries is Requests. We will be using requests library to implement GET and POST request in this article.
You can install requests library using the following command:
pip install requests |
Make a GET Request
We can make a GET request using get() method:
Example 1:
# import requests module |
Output:
<Response [200]> |
Example 2
# import requests module |
Output:
https://api.github.com/ |
Make a POST Request
We can make a POST request using post() method:
Example 1:
import requests |
Output:
{ |