Installing and Using Requests
00:00
So you know what an API is. But how do you actually interact with one? In this course, we will be using a brilliant library called requests to do all of the heavy lifting for us.
00:12
requests is a very popular library for sending, as you might have guessed, requests, as well as receiving and parsing responses from APIs. To install it, you are going to use pip in the terminal with the following command: pip install requests.
00:29
Now you are ready to make your first request. To do so, you are going to use the requests.get function. You will need to provide a URL to an API.
00:38
In this example, you will use the emojis API from GitHub, https://api.github.com/emojis. Switching over to the REPL, you’re going to start by importing the requests library you just installed.
00:52
Next up, you can save the URL to the emojis API as a variable. This is the URL you saw in the last slide. Finally, you can send your first request by using the requests.get function, which you saw on the last slide.
01:10 The only argument it needs right now is the URL of the API you want to send your request to. After hitting enter, you should receive a response. Hooray! You successfully sent a request and received a response from the server.
01:25 You’ll find out what this number means and more about the response in the next lesson.
Become a Member to join the conversation.
