Menu
Coddy logo textTech

Manipulating requests Response

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

Once you either get() or post() into an API, you will receive a response object which we stored in the response variable in our last examples.


As we learned in the JSON lesson, these responses are in JSON format or in Python's native dictionary format.

 

To receive the JSON format of your response. You have to say,

data = response.json()

You can then parse through the necessary values in the response, using the keying method of the dictionary.

challenge icon

Challenge

Medium

Instructions:

  1. Send a GET request to: https://jsonplaceholder.typicode.com/users/1
  2. Save the requests.get() object to a variable called response
  3. Parse and save response.json() into a variable called data
  4. Use the keying method to save data["name"] into a variable called result
  5. Print result - it should always display: Leanne Graham

Try it yourself

import requests

# Step 1: Send GET request
response = # Your code here

# Step 2: Parse JSON response
data = # Your code here

# Step 3: Get the name
result = # Your code here

# Step 4: Print the result
print(result)

All lessons in API in Python