Working with APIs
程序员文章站
2022-06-04 13:30:36
...
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 pplication program interface (API) is a set a methods and tools that allow different applications to interact with each other. APIs are hosted on web servers.
- Programmers use APIS to retrieve data as it becomes available, which allows the client to quickly and effectively retrieve data the 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 to ensure that 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 with 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 right 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; you don’t have the right permissions to see it.
- 404 - The server didn’t find the resource you tried to access.
Resources
上一篇: API
下一篇: quill富文本编辑器 API
推荐阅读
-
详解spring cloud整合Swagger2构建RESTful服务的APIs
-
HTML5 Convas APIs方法详解
-
详解spring cloud整合Swagger2构建RESTful服务的APIs
-
Eclipse中怎么使用Working set管理项目?
-
微信小程序 wx.uploadFile在安卓手机上面the same task is working问题解决
-
Working with Python subprocess
-
HTML5 Convas APIs方法详解
-
HTML5 APIs程序员指南
-
.net core EFCore CodeFirst 迁移出现【No project was found. Change the current working directory or use the --project option. 】
-
Eclipse中怎么使用Working set管理项目?