Building an HTTP client with requests
Being able to interact with RESTful APIs based on HTTP is an increasingly common task in projects in any programming language. In Python, we also have the option of interacting with a REST API in a simple way with the requests
module. In this section, we will review the different ways in which we can interact with an HTTP-based API using the Python requests
package.
One of the best options within the Python ecosystem for making HTTP requests is the requests
module. You can install the requests
library in your system in a straightforward manner with the pip
command:
pip3 install requests
This module is available on the PyPi
repository as the httpx package. It can either be installed through pip
or downloaded from https://requests.readthedocs.io/en/master, which stores the documentation.
To test the library in our script, just import it as we do with other modules. Basically, requests
is a wrapper of urllib.request
, along with other Python...