Menu
Coddy logo textTech

requests Method to Retrieve

Lesson 5 of 10 in Coddy's API in Python course.

If you want to retrieve some information from an API, we have to use a method called .get().

This get() method takes a parameter of the URL and the API key.

Note: Sometimes API Key may not be necessary. It depends upon the API Server.

So, the code would look like this:

import requests

response = requests.get("https://www.API_URL.com", "API_KEY_IF_NECESSARY")
print(response)

Here, we are storing the method into a response variable so it's easier to access the response.

challenge icon

Challenge

Easy

Send a get request to "https://reqres.in" and save it to a response variable.

Try it yourself

import requests
# Write code here

# Don't change below this line
print(response.status_code)
print(response.url)

All lessons in API in Python