首页 > 代码库 > Working with Data Sources
Working with Data Sources
1. The API is the link to request data from the host.
2. A endpoint is a route to retrive different data from the API.
3. Status codes indicate information about what happened with a request. Here are some codes that are relevant to GET requests:
200
-- everything went okay, and the result has been returned (if any)301
-- the server is redirecting you to a different endpoint. This can happen when a company switches domain names, or an endpoint name is changed.401
-- the server thinks you‘re not authenticated. This happens when you don‘t send the right credentials to access an API (we‘ll talk about this in a later mission).400
-- the server thinks you made a bad request. This can happen when you don‘t send along the right data, among other things.403
-- the resource you‘re trying to access is forbidden -- you don‘t have the right permissions to see it.404
-- the resource you tried to access wasn‘t found on the server
4. json.dumps can convert the list and dictionary to string:
best_food_chains_string = json.dumps(best_food_chains)
Json.loads can convert the string to lists or dictionaries.
fast_food_franchise_2 = json.loads(fast_food_franchise_string)
5. I can get the content of a response as a Python object by using .json() method.
data = http://www.mamicode.com/response.json()
6. .header property shows the content that how data was generated and how to decode it.
Working with Data Sources