Working with APIs in Python Flashcards
1
Q
Import the a Python library to work with APIs
A
import requests
2
Q
Send a get request to an endpoint
A
response = requests.get(“Endpoint_address_as_string”)
3
Q
Examine the status code from a response object
A
response.status_code
4
Q
Import a library to work with JSON
A
import jason
5
Q
Use a function from json library to convert a Python object into a string
A
new_string = json.dumps( Python_Object )
6
Q
Use a function from json library to convert a JSON string into a Python object
A
Python_Object = json.loads( JASON_String )
7
Q
Retrieve a Python object from a response object
A
response.json()
8
Q
Retrieve a JSON text from a response object
A
response.content
9
Q
Retrieve metadata from a response object
A
response.headers #returns as a dictionary object