<jupyter_start><jupyter_text>IST256 Lesson 11  Web Services and API's- Assigned Reading  https://ist256.github.io/spring2020/readings/Web-APIs-In-Python.html Links- Participation: [https://poll.ist256.com](https://poll.ist256.com)  (Sign in with *<EMAIL> and your SU Password.)- Class Chat: [https://chat.ist256.com](https://chat.ist256.com)  (Microsoft Teams.)  FEQT (Future Exam Questions Training) 1What prints on the last line of this program?<jupyter_code>import requests
w = 'http://httpbin.org/get'
x = { 'a' :'b', 'c':'d'}
z = { 'w' : 'r'}
response = requests.get(w, params = x, headers = z)
print(response.url)<jupyter_output>http://httpbin.org/get?a=b&c=d<jupyter_text>A. `http://httpbin.org/get?a=b`  B. `http://httpbin.org/get?c=d`  C. `http://httpbin.org/get?a=b&c=d`  D. `http://httpbin.org/get`    Vote Now: [https://poll.ist256.com](https://poll.ist256.com)  FEQT (Future Exam Questions Training) 2Which line de-serializes the response?<jupyter_code>import requests                 # <= load up a bunch of pre-defined functions from the requests module
w = 'http://httpbin.org/ip'     # <= string
response = requests.get(w)      # <= w is a url. HTTP POST/GET/PUT/DELETE Verbs of HTTP
response.raise_for_status()     # <= response code.if not 2??, throw exception 4 client 5 server
d = response.json()         #<= de-serilaize!
d['origin']<jupyter_output><empty_output><jupyter_text>A. `2`  B. `3`  C. `4`  D. `5`    Vote Now: [https://poll.ist256.com](https://poll.ist256.com)  Agenda- Lesson 10 Homework Solution- A look at web API's - Places to find web API's- How to read API documentation- Examples of using API's  Connect Activity**Question:** A common two-step verification process uses by API's discussed in the reading isA. `OAUTH2`  B. `Multi-Factor`  C. `API Key in Header`  D. `JSON format`   Vote Now: [https://poll.ist256.com](https://poll.ist256.com)  The Web Has Evolved…. From  **User-Consumption**- Check the news / weather in your browser- Search the web for "<NAME>"- **Internet is for people**.To **Device-Consumption**- Get news/ weather alerts on your Phone- Ask Alexa “When is <NAME> Birthday?"- **Internet of Things**.  Device Consuption Requires a Web API- API = Application Program Interface. In essence is a formal definition of functions exposed by a service.- Web API - API which works over HTTP.- In essence you can call functions and access services using the HTTP protocol.- Basic use starts with an HTTP request and the output is typically a JSON response.- We saw examples of this previously with:  - Open Street Maps Geocoding: https://nominatim.openstreetmap.org/search?q=address&format=json  - Weather Data Service: https://openweathermap.org- Thanks to APIs' we can write programs to interact with a variety of services.    Finding API's requires research… Start googling…"foreign exchange rate api"![image.png](attachment:image.png)  Then start reading the documentation on fixer.io …![image.png](attachment:image.png)  Then start hacking away in Python …<jupyter_code>import requests
url = "http://data.fixer.io/api/latest?access_key=159f1a48ad7a3d6f4dbe5d5a"
response = requests.get(url)
response.json()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13350047007207771, 'fraction_numerical': 0.020683171419617674, 'mean_word_length': 4.293532338308458, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 15, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '41949', 'license': 'Apache-2.0', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1005, 'n_words': 337, 'path': 'lessons/11-webapis/Slides.ipynb', 'repo_name': 'IST256/spring2022', 'size': '3232'}