Consuming the RESTful API
Now that you have implemented an API, you can consume it in a programmatic manner from other applications. You can interact with the API using the JavaScript Fetch API in the frontend of your application, in a similar fashion to the functionalities you built in Chapter 6, Sharing Content on Your Website. You can also consume the API from applications built with Python or any other programming language.
You are going to create a simple Python application that uses the RESTful API to retrieve all available courses and then enroll a student in all of them. You will learn how to authenticate against the API using HTTP basic authentication and perform GET
and POST
requests.
We will use the Python Requests library to consume the API. We used Requests in Chapter 6, Sharing Content on Your Website, to retrieve images by their URL. Requests abstracts the complexity of dealing with HTTP requests and provides a very simple interface to consume HTTP services...