css/Bootstrap/html Flashcards
Appannie only accepts requests from
https
the appannie api domain is
https://api.appannie.com/
Python: The requests library allows you to
connect to APIs
A site designed for testing API calls is
http://httpbin.org/
requests: r = requests.get(“http://httpbin.org/get”) returns a
response object
requests: To return the status code of a response object, type
r.status_code for the code
or
r.ok for a check on all of them
requests: To return the header of a response object, type
r.headers
or
r.headers.keys()
Python: Most APIs return
JSON data
requests: To return just one value from the header by passing in the key name, type
r.headers[“Key name”]
requests: To see the text of a response object, type
r.text
requests: To return the text of a response object in json format, type
r.json()
requests: To create an object through an API usually requires a
POST request and a payload of data.
requests: payloads are usually
dictionaries
eg,
payload = {“content”: “My string”, “user_id”: 1000}
requests: To create a post request, type
r = requests.post(“http://httpbin.org/”, params=payload)
API: A RESTful API request is fundamentally just
a url with parameters
requests: To send data in a payload where a key represents a list, type
payload = {list_name[]: [1000, 2000]}
requests: To send a delete request, type
r = requests.delete(“http://httpbin.org/delete”, params=payload)
requests: To see if your request was redirected, type
r.history
requests: To disallow redirects for a request, type
r = requests.get(“http://httpbin.org”, allow_redirects=False)
APIs usually do authentication through
public and private keys.
The two main type of authentication for websites (not APIs), use for authentication are
HTTPBasicAuth and HTTPDigestAuth
requests: to create a request with a HTTPBasicAuth, type
from requests.auth import HTTPBasicAuth
r = requests.get(“http://httpbin.org”, auth=HTTPBasicAuth(“username”, “password”))
requests: requests also support authentication through
oauth
json: To parse a list of dicts into a df, type
for x in r.json()["proposals"]: df = df.append([[ x["costToComplete"], x["freeShipping"], x["gradeLevel"]["id"], x["gradeLevel"]["name"] ]], ignore_index=True)
Home
Contact
-/header> ```- must be
elements will never wrap, type