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:
$ pip install requests
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 modules, to provide the REST structure with simple methods, so we have the get
, post
, put
, update
, delete
, head
, and options
methods, which are all the requisite methods for interacting with a RESTful...