0% found this document useful (0 votes)
32 views2 pages

Working With Apis: Takeaways: Syntax

The document discusses key concepts for working with APIs including accessing response content and headers, JSON formatting, using the requests and JSON libraries, endpoints, and status codes like 200, 301, 401, 403, and 404.

Uploaded by

tomepa1655
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Working With Apis: Takeaways: Syntax

The document discusses key concepts for working with APIs including accessing response content and headers, JSON formatting, using the requests and JSON libraries, endpoints, and status codes like 200, 301, 401, 403, and 404.

Uploaded by

tomepa1655
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Working with APIs: Takeaways

by Dataquest Labs, Inc. - All rights reserved © 2020

Syntax
• Accessing the content of the data the server returns:
response.content

• Importing the JSON library:


import json

• Getting the content of a response as a Python object:


response.json()

• 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.

• The JSON library has two main methods:

• dumps — takes in a Python object and converts it to a string.

• loads — takes in a JSON string and converts it to a Python object.

• We use the requests library to communicate with the web server and retrieve the data.

• An endpoint is a server route for retrieving specific data from an API.

• Web servers return status codes every time they receive an API request.

• Status codes that are relevant to GET requests:

• 200 — everthing went okay, and the server returned a result.

• 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

• JSON Library Documentation

Takeaways by Dataquest Labs, Inc. - All rights reserved © 2020

You might also like