Skip to content

Commit 18c6b69

Browse files
committed
Fix typos and clean up excluded code
1 parent 12d62c2 commit 18c6b69

File tree

1 file changed

+3
-223
lines changed

1 file changed

+3
-223
lines changed

content/web-apis.ipynb

Lines changed: 3 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
":::{objectives}\n",
1717
"- Understand a web server and API and why might you need to talk to one.\n",
1818
"- Basics of the [requests](https://requests.readthedocs.io/en/latest/) Python library\n",
19-
"- Some lightweightRecommendations on saving data when you get to more serious data download.\n",
19+
"- Some lightweight recommendations on saving data when you get to more serious data download.\n",
2020
":::\n",
2121
"\n"
2222
]
@@ -78,7 +78,7 @@
7878
"source": [
7979
"## Retrieve data from API\n",
8080
"\n",
81-
"An **API (Applicaiton Programming Interface)** is the definition of the way computer programs communicate with each other. We use Requests to connect to the API of a web server, tell it what we want, and it returns it to us. This is called the **request-response** cycle.\n",
81+
"An **API (Application Programming Interface)** is the definition of the way computer programs communicate with each other. We use Requests to connect to the API of a web server, tell it what we want, and it returns it to us. This is called the **request-response** cycle.\n",
8282
"\n",
8383
"We can find a list of some free APIs (available without authentication) at <https://apipheny.io/free-api/#apis-without-key> ."
8484
]
@@ -1009,226 +1009,6 @@
10091009
":::\n",
10101010
"\n"
10111011
]
1012-
},
1013-
{
1014-
"cell_type": "code",
1015-
"execution_count": null,
1016-
"id": "fe96c62a-cfb1-42bf-9a8d-307dbb4beeec",
1017-
"metadata": {},
1018-
"outputs": [],
1019-
"source": []
1020-
},
1021-
{
1022-
"cell_type": "code",
1023-
"execution_count": null,
1024-
"id": "84032754-dfd1-4a44-b1ff-5347a426ed53",
1025-
"metadata": {},
1026-
"outputs": [],
1027-
"source": []
1028-
},
1029-
{
1030-
"cell_type": "code",
1031-
"execution_count": null,
1032-
"id": "f9b74503-a882-4514-85a3-2f25ed3d4cc8",
1033-
"metadata": {},
1034-
"outputs": [],
1035-
"source": []
1036-
},
1037-
{
1038-
"cell_type": "code",
1039-
"execution_count": null,
1040-
"id": "69621f7d-efad-49ec-93b9-7630d05bf1c4",
1041-
"metadata": {},
1042-
"outputs": [],
1043-
"source": []
1044-
},
1045-
{
1046-
"cell_type": "code",
1047-
"execution_count": null,
1048-
"id": "3c991c85-217f-4c39-bf56-251237b1f89a",
1049-
"metadata": {},
1050-
"outputs": [],
1051-
"source": []
1052-
},
1053-
{
1054-
"cell_type": "code",
1055-
"execution_count": null,
1056-
"id": "02609972-b13d-4183-a340-16dd0708038f",
1057-
"metadata": {},
1058-
"outputs": [],
1059-
"source": []
1060-
},
1061-
{
1062-
"cell_type": "code",
1063-
"execution_count": null,
1064-
"id": "07be9348-015f-4de6-9380-91cfeeaaeae0",
1065-
"metadata": {},
1066-
"outputs": [],
1067-
"source": []
1068-
},
1069-
{
1070-
"cell_type": "code",
1071-
"execution_count": null,
1072-
"id": "8c766f5d-a3e0-46fb-857d-46c86da5a92b",
1073-
"metadata": {},
1074-
"outputs": [],
1075-
"source": []
1076-
},
1077-
{
1078-
"cell_type": "markdown",
1079-
"id": "e1fe162b-7bb8-49a7-802a-71ccb910785d",
1080-
"metadata": {
1081-
"tags": []
1082-
},
1083-
"source": [
1084-
"## < Excluded stuff >"
1085-
]
1086-
},
1087-
{
1088-
"cell_type": "code",
1089-
"execution_count": 24,
1090-
"id": "6b0628fe-5918-46bd-8516-2a1e626a9faf",
1091-
"metadata": {},
1092-
"outputs": [],
1093-
"source": [
1094-
"# Import modules\n",
1095-
"import requests\n",
1096-
"\n",
1097-
"# URL of the activity API end point\n",
1098-
"url = \"http://www.boredapi.com/api/activity/\"\n",
1099-
"\n",
1100-
"# Make an example custom header with a \n",
1101-
"headers = {\n",
1102-
" 'User-Agent': 'python-requests/2.28.1',\n",
1103-
" 'Accept-Encoding': 'gzip, deflate, br',\n",
1104-
" 'Accept': '*/*',\n",
1105-
" 'Connection': 'keep-alive',\n",
1106-
" }\n",
1107-
"\n",
1108-
"# Pass the custom headers to get() function as an argument\n",
1109-
"response = requests.get(url, headers=headers)"
1110-
]
1111-
},
1112-
{
1113-
"cell_type": "code",
1114-
"execution_count": 25,
1115-
"id": "4ee093df-682c-4230-9537-4e5dca4b4c9a",
1116-
"metadata": {},
1117-
"outputs": [
1118-
{
1119-
"data": {
1120-
"text/plain": [
1121-
"'Response headers'"
1122-
]
1123-
},
1124-
"metadata": {},
1125-
"output_type": "display_data"
1126-
},
1127-
{
1128-
"data": {
1129-
"text/plain": [
1130-
"{'Server': 'Cowboy',\n",
1131-
" 'Connection': 'keep-alive',\n",
1132-
" 'X-Powered-By': 'Express',\n",
1133-
" 'Access-Control-Allow-Origin': '*',\n",
1134-
" 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',\n",
1135-
" 'Content-Type': 'application/json; charset=utf-8',\n",
1136-
" 'Content-Length': '150',\n",
1137-
" 'Etag': 'W/\"96-6an0WFtY/cZOy49oLsoitk6p1XY\"',\n",
1138-
" 'Date': 'Mon, 21 Nov 2022 19:30:59 GMT',\n",
1139-
" 'Via': '1.1 vegur'}"
1140-
]
1141-
},
1142-
"metadata": {},
1143-
"output_type": "display_data"
1144-
},
1145-
{
1146-
"data": {
1147-
"text/plain": [
1148-
"''"
1149-
]
1150-
},
1151-
"metadata": {},
1152-
"output_type": "display_data"
1153-
}
1154-
],
1155-
"source": [
1156-
"# Show the headers of the response sent to us by the server\n",
1157-
"display(\"Response headers\")\n",
1158-
"display(dict(response.headers))\n",
1159-
"display(\"\")"
1160-
]
1161-
},
1162-
{
1163-
"cell_type": "code",
1164-
"execution_count": 26,
1165-
"id": "dd61d3b8-21a2-449f-a8a3-a9fcdb345620",
1166-
"metadata": {},
1167-
"outputs": [
1168-
{
1169-
"data": {
1170-
"text/plain": [
1171-
"'Custom request headers'"
1172-
]
1173-
},
1174-
"metadata": {},
1175-
"output_type": "display_data"
1176-
},
1177-
{
1178-
"data": {
1179-
"text/plain": [
1180-
"{'User-Agent': 'python-requests/2.28.1',\n",
1181-
" 'Accept-Encoding': 'gzip, deflate, br',\n",
1182-
" 'Accept': '*/*',\n",
1183-
" 'Connection': 'keep-alive'}"
1184-
]
1185-
},
1186-
"metadata": {},
1187-
"output_type": "display_data"
1188-
}
1189-
],
1190-
"source": [
1191-
"# Show the customized request headers\n",
1192-
"# (This has the new user-agent.)\n",
1193-
"display(\"Custom request headers\")\n",
1194-
"display(dict(response.request.headers))"
1195-
]
1196-
},
1197-
{
1198-
"cell_type": "markdown",
1199-
"id": "0cbb46f5-ee14-418a-a95a-370f0d9b8225",
1200-
"metadata": {},
1201-
"source": []
1202-
},
1203-
{
1204-
"cell_type": "markdown",
1205-
"id": "f4c29ed4-b717-4b80-a00f-f7d2237e1fce",
1206-
"metadata": {
1207-
"tags": []
1208-
},
1209-
"source": [
1210-
"### Exercise: Examine authentication methods\n",
1211-
"\n",
1212-
"The APIs we have looked at in this session have been _open_ / _public_, that is, they have not required authentication. However, access to most APIs is restricted using authentication methods. This allows the API provider to e.g. provide access to paying customers only or control the number of users.\n",
1213-
"\n",
1214-
"Most commonly, the authentication methods require the use of _API keys_, that is, a username and a password. The API keys must be attached to each request. Again, similarly to parameters and headers, we can pass them to the _get_ function as an argument.\n",
1215-
"\n",
1216-
"The authentication methods supported by _Requests_ with syntax examples can be found here\n",
1217-
"\n",
1218-
"https://requests.readthedocs.io/en/latest/user/authentication/\n"
1219-
]
1220-
},
1221-
{
1222-
"cell_type": "code",
1223-
"execution_count": 27,
1224-
"id": "4bf84e15-c050-4d8d-8a97-1ffc96e2958d",
1225-
"metadata": {
1226-
"tags": []
1227-
},
1228-
"outputs": [],
1229-
"source": [
1230-
"# No code"
1231-
]
12321012
}
12331013
],
12341014
"metadata": {
@@ -1247,7 +1027,7 @@
12471027
"name": "python",
12481028
"nbconvert_exporter": "python",
12491029
"pygments_lexer": "ipython3",
1250-
"version": "3.9.2"
1030+
"version": "3.8.13"
12511031
}
12521032
},
12531033
"nbformat": 4,

0 commit comments

Comments
 (0)