Consuming the API
By making our views available via URLs, we have created our first API endpoints. Let’s now try our own API. Ensure that your server is running with the following command:
python manage.py runserver
We are going to use curl to consume the API. curl is a command-line tool that allows you to transfer data to and from a server. If you are using Linux, macOS, or Windows 10/11, curl is very likely included in your system. However, you can download curl from https://curl.se/download.html.
Open the shell and retrieve the URL http://127.0.0.1:8000/api/subjects/ with curl, as follows:
curl http://127.0.0.1:8000/api/subjects/
You will get a response similar to the following one:
[
{
"id":1,
"title":"Mathematics",
"slug":"mathematics"
},
{
"id":2,
"title":"Music",
"slug":"music"
}...