In this lesson we will look more at what is composed in a response and ways we might use it.
We start by making a generic function for making get and put calls.
Why don't we look at a response from the previous lesson and double check its type. Please run the following code before proceeding.
Uh oh! It looks like the response is still a string! We won't be able to index into it like a normal dictionary. To fix this, we may use the json library.
Using the same functions written in the previous code block, we may
make the same request and then do something with the response.
We may use json.loads to convert a string to a
dictionary. This assumes the string is formatted with proper
quotation marks and curly brackets such that it can be parsed.
After this, we may use it like a normal dictionary!
We may expect a response to contain various attributes. Such as status, headers, and body, which corresponds to data.