Working With Apis: Takeaways: Syntax
Working With Apis: Takeaways: Syntax
Syntax
• Accessing the content of the data the server returns:
response.content
• Accessing the information on how the server generated the data, and how to decode the data:
response.headers
Concepts
• An application program interface (API) is a set of methods and tools that allows different
applications to interact with each other. Web servers host APIs.
• Programmers use APIs to retrieve data as it becomes available, which allows the client to quickly and
effectively retrieve data that changes frequently.
• JavaScript Object Notation (JSON) format is the primary format for sending and receiving data
through APIs. JSON encodes data structures like lists and dictionaries as strings so machines can
read them easily.
• We use the requests library to communicate with the web server and retrieve the data.
• Web servers return status codes every time they receive an API request.
• 301 — the server is redirecting you to a different endpoint. This can happen when a
company switches domain names or an endpoint's name has changed.
• 401 — the server thinks you're not authenticated. This happens when you don't supply the
correct credentials.
• 400 — the server thinks you made a bad request. This can happen when you don't send the
information the API requires to process your request.
• 403 — the resource you're trying to access is forbidden, and you don't have the right
permissions to see it.
• 404 — the server didn't find the resource you tried to access.
Resources
• Requests library Documentation