forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathw04-01.html
381 lines (349 loc) · 12.1 KB
/
w04-01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>REST</title>
<meta name="description" content="API Overview">
<meta name="author" content="John D. Martin III">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/theme/black.css" id="theme">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css">
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section data-background-image="./api.png" data-background-position="left" data-background-opacity="0.25">
<h2>API Overview</h2>
<h3>
COMP 426 w04.01
</h3>
</section>
<section data-background-color="">
<h2>Agenda</h2>
<ol>
<li>REST API</li>
<li>Why REST?</li>
<li>Constraints</li>
<li>Resources</li>
<li>How do we interact with a REST API?</li>
<li>Methods</li>
<li>Alternatives?</li>
</ol>
</section>
<section data-background-color="">
<section data-background-color="#4287f5">
<h2 data-id="code-title">REST</h2>
</section>
<section data-background-color="#3873d1">
<h2 data-id="code-title"><em>RE</em><span style="color:#aaa">presentational</span> <em>S</em><span style="color:#aaa">tate</span> <em>T</em><span style="color:#aaa">ransfer</span></h2>
</section>
</section>
<section data-background-color="">
<section data-background-color="#49018c">
<h2 data-id="code-title">RESTful constraints</h2>
</section>
<section data-background-color="#60018c">
<h2 data-id="code-title">Uniform interface</h2>
</section>
<section data-background-color="#7c018c">
<h2 data-id="code-title">Client <=> Server</h2>
</section>
<section data-background-color="#8c0181">
<h2 data-id="code-title">Stateless</h2>
</section>
<section data-background-color="#8c0167">
<h2 data-id="code-title">Cacheable</h2>
</section>
<section data-background-color="#8c0139">
<h2 data-id="code-title">Layered system</h2>
</section>
<section data-background-color="#8c010f">
<h2 data-id="code-title">Code-on-demand</h2>
</section>
</section>
<section data-background-color="">
<section data-background-color="">
<h2 data-id="code-title">Data elements</h2>
</section>
<section data-background-color="">
<h2 data-id="code-title">Resources and messages</h2>
<p>Me, your instructor</p>
</section>
<section data-background-color="">
<h2 data-id="code-title">Resource identifier</h2>
<pre data-id="code-animation"><code data-trim>
Uniform Resource Identifier (URI): John D. Martin III
Uniform Resource Locator (URL): https://johndmart.in
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">Representation</h2>
<img src="./john_face.jpg" alt="Picture of John wearing a UNC baseball cap backwards and a black cloth mask inside a car, looking away from the camera" style="border-radius: 50%">
</section>
<section data-background-color="">
<h2 data-id="code-title">Representation metadata</h2>
<pre data-id="code-animation"><code>
<img src="./john_face.jpg" alt="Picture of John wearing a UNC baseball cap backwards and a black cloth mask inside a car, looking away from the camera">
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">Representation metadata</h2>
<pre data-id="code-animation"><code>
alt="Picture of John wearing a UNC baseball cap backwards and a black cloth mask inside a car, looking away from the camera"
</code></pre>
<pre data-id="code-animation"><code data-trim>
$ ls -lah john_face.jpg
-rw-r--r-- 1 john john 34K Feb 10 11:31 john_face.jpg
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">Resource metadata</h2>
<pre data-id="code-animation"><code data-trim>
Created: 1980-09-05T00:35:00-5:00
Last major update: 2021-09-05T00:35:00-5:00
Origin: 43.0125°,-83.6875°
Current: 35.9049°,-79.0469°
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">Control data</h2>
<pre data-id="code-animation"><code data-trim>
Cacheable: true
In-cache: true
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">Message: JSON</h2>
<pre data-id="code-animation"><code data-trim>
{
"uri": "John D. Martin III",
"url": "https://johndmart.in",
"image": {
"url": "./john_face.jpg",
"modified": "2022-02-10T11:31:00-5:00"
},
"location": {
"origin": [ "43.0125", "-83.6875" ],
"current": [ "35.9049", "-79.0469" ]
},
"version": {
"initial": [ "v0.0.0", "1980-09-05T00:35:00-5:00" ],
"major": [ "v41.0.0", "2021-09-05T00:35:00-5:00" ],
"current": [ "v41.5.5", "2022-02-10T00:35:00-5:00" ]
},
"cache": {
"cacheable": "true",
"in-cache": "true"
}
}
</code></pre>
</section>
</section>
<section data-background-color="">
<section data-background-color="#fcba03">
<h2 data-id="code-title">Methods</h2>
<ol>
<li>Create</li>
<li>Read</li>
<li>Update</li>
<li>Delete</li>
</ol>
</section>
<section data-background-color="#0328fc">
<h2 data-id="code-title">HTTP Methods</h2>
<ol>
<li>POST</li>
<li>GET</li>
<li>PUT</li>
<li>PATCH</li>
<li>DELETE</li>
</ol>
</section>
<section data-background-color="#018c1b">
<h2 data-id="code-title">Corresponding Methods</h2>
<ol>
<li>POST == Create</li>
<li>GET == Read</li>
<li>PUT == Update (replace)</li>
<li>PATCH == Update (modify)</li>
<li>DELETE == Delete</li>
</ol>
</section>
</section>
<section data-background-color="">
<section data-background-color="">
<h2 data-id="code-title">Messages</h2>
</section>
<section data-background-color="">
<h2 data-id="code-title">GET URI</h2>
<pre data-id="code-animation"><code data-trim>
curl -X GET https://johndmart.in/some/api/endpoint/info/
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">JSON Body</h2>
<pre data-id="code-animation"><code data-trim>
{
"uri": "John D. Martin III",
"url": "https://johndmart.in",
"image": {
"url": "./john_face.jpg",
"modified": "2022-02-10T11:31:00-5:00"
},
"location": {
"origin": [ "43.0125", "-83.6875" ],
"current": [ "35.9049", "-79.0469" ]
},
"version": {
"initial": [ "v0.0.0", "1980-08-10T00:35:00-5:00" ],
"major": [ "v41.0.0", "2021-08-10T00:35:00-5:00" ],
"current": [ "v41.6.0", "2022-02-10T00:35:00-5:00" ]
},
"cache": {
"cacheable": "true",
"in-cache": "true"
}
}
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">URL encoded Body</h2>
<pre data-id="code-animation"><code data-trim>
https://johndmart.in/some/api/endpoint/?uri=John%20D.%20Martin%20III&
url=http%3A%2F%2Fjohndmart.in&imgurl=.%2Fjohn_face.jpg&
imgmodified=2022-02-10T11%3A31%3A00-5%3A00&
originlat=43.0125&originlong=-83.6875&curlat=35.9049&
curlong=-79.0469&versioninit=v0.0.0&
timeinit=20221980-08-10T00%3A35%3A00-5%3A00&majorupdate=v41.0.0&
timemaj=2021-09-05T00%3A35%3A00-5%3A00&cur=v41.5.5&
timecur=2022-02-10T00%3A35%3A00-5%3A00&cacheable=true&cached=true
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">POST URI</h2>
<pre data-id="code-animation"><code data-trim>
curl -X POST -d "uri=John%20D.%20Martin%20III&
url=http%3A%2F%2Fjohndmart.in&imgurl=.%2Fjohn_face.jpg
&imgmodified=2022-02-10T11%3A31%3A00-5%3A00"
https://johndmart.in/some/api/endpoint/send/
</code></pre>
</section>
</section>
<section data-background-color="#018c88">
<h2 data-id="code-title">Alternatives?</h2>
</section>
<section data-background-color="">
<section data-background-color="">
<h2 data-id="code-title">SOAP</h2>
</section>
<section data-background-color="">
<h2 data-id="code-title">Simple Object Access Protocol</h2>
<ol>
<li>Strict standard</li>
<li>XML only</li>
<li>REST can use SOAP, but SOAP cannot use REST</li>
<li>More complex to implement than REST</li>
<li>Used for secure transactions</li>
<li>Atomicity Consistency Isolation Durability (ACID) compliant</li>
<li>Newer than REST (ca. mid-00s)</li>
</ol>
</section>
<section data-background-color="">
<pre data-id="code-animation"><code data-trim>
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://www.example.org">
<soap:Header>
</soap:Header>
<soap:Body>
<m:GetInfo>
<m:ResourceName>John D. Martin III</m:ResourceName>
</m:GetInfo>
</soap:Body>
</soap:Envelope>
</code></pre>
</section>
</section>
<section data-background-color="">
<section data-background-color="">
<h2 data-id="code-title">GraphQL</h2>
</section>
<section data-background-color="">
<h2 data-id="code-title">Graph Query Language</h2>
<ol>
<li>Data-oriented</li>
<li>Very specific</li>
<li>No waste</li>
<li>New school (2015)</li>
</ol>
</section>
<section data-background-color="">
<h2 data-id="code-title">REST: get user name</h2>
<pre data-id="code-animation">REST: get user name<code data-trim>
GET /users/123
/**
{
"id": "123",
"name": "John D. Martin III",
"birthdate": "1980-08-10",
"location": {
"city": "Chapel Hill",
"state": "North Carolina",
"country": "United States of America"
}
}
*/
</code></pre>
</section>
<section data-background-color="">
<h2 data-id="code-title">GraphQL: get user name</h2>
<pre data-id="code-animation"><code data-trim>
query {
User (id: "123"){
name
}
}
</code></pre>
</section>
</section>
<section data-background-color="">
<section data-background-color="">
<h2 data-id="code-title">RPC</h2>
</section>
<section data-background-color="">
<h2 data-id="code-title">Remote Procedure Call</h2>
<ol>
<li>Request <=> Response</li>
<li>Execute remote server code as if local</li>
<li>Client agnostic of code location</li>
<li>Action-oriented</li>
<li>Old school (ca. 1981, but conceptually older)
</ol>
</section>
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script>
Reveal.initialize();
const loadScript = src => {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.type = 'text/javascript';
script.onload = resolve;
script.onerror = reject;
script.src = src;
document.head.append(script);
})
}
loadScript( 'plugin/highlight/highlight.js' ).then(() => {
Reveal.registerPlugin( RevealHighlight )
})
</script>
</body>
</html>