-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.html
164 lines (151 loc) · 6.61 KB
/
3.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Advanced Web Dev</title>
<meta name="author" content="Eric Moynihan" />
<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="reveal/css/reset.css" />
<link rel="stylesheet" href="reveal/css/reveal.css" />
<link rel="stylesheet" href="reveal/css/theme/black.css" id="theme" />
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="reveal/lib/css/monokai.css" />
<!-- Printing and PDF exports -->
<script>
var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = window.location.search.match(/print-pdf/gi)
? "reveal/css/print/pdf.css"
: "reveal/css/print/paper.css";
document.getElementsByTagName("head")[0].appendChild(link);
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<img src="https://cdn-assets-cloud.frontify.com/local/frontify/h_lNxVXLqrDqb2kyrixW3lMmUl7n-aBRzJUzyvzD7_9FpVMt61zcnJ81BDOqdkOndY8i0eAwn6Wh0ML1aAgbhjOhufnBG8Tz7OVGBhGqrknPlL9fOTjbQj2eRqycd0zF?width=2400" style="border: 0; background: transparent; width: 35%;" />
<h1>Advanced Web Development</h1>
<p><b>Week 3</b>: REST API's</p>
<p>By <a href="https://github.com/ericm">Eric Moynihan</a></p>
</section>
<section style="text-align: left;">
<h1>What is REST?</h1>
<p><b>RESTful</b> web applications provide an interface to transfer <i>state</i> through <i>stateless</i> operations.</p>
</section>
<section style="text-align: left;">
<h1>State</h1>
<p>State in this context means that our backend application will remember previous user interactions. This means that it can provide information to a client about whether or not a user is online.</p>
</section>
<section style="text-align: left;">
<h1>rest api requests</h1>
<p>Let's say you send a http GET request to a REST API on an endpoint like <b>/user/eric</b></p>
<p>The middlewear will check the sender's credentials, the controller will process this request, it will then query a DB and construct a response with a body of JSON</p>
</section>
<section style="text-align: left;">
<h1>HTTP Response</h1>
<p>I sent a request to <b>https://api.github.com/users/ericm</b> and this was the response:</p>
<pre><code class="hljs">
{
"login": "ericm",
"id": 29894839,
"node_id": "MDQ6VXNlcjI5ODk0ODM5",
"avatar_url": "https://avatars3.githubusercontent.com/u/29894839?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ericm",
"html_url": "https://github.com/ericm",
"followers_url": "https://api.github.com/users/ericm/followers",
"following_url": "https://api.github.com/users/ericm/following{/other_user}",
"gists_url": "https://api.github.com/users/ericm/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ericm/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ericm/subscriptions",
"organizations_url": "https://api.github.com/users/ericm/orgs",
"repos_url": "https://api.github.com/users/ericm/repos",
"events_url": "https://api.github.com/users/ericm/events{/privacy}",
"received_events_url": "https://api.github.com/users/ericm/received_events",
"type": "User",
"site_admin": false,
"name": "Eric Moynihan",
"company": null,
"blog": "https://moynihan.io",
"location": "Cork, Ireland",
"email": null,
"hireable": true,
"bio": "CS student at University College Cork.\r\nFreelance Web Developer.\r\nQualified Lifeguard. Profile picture is original artwork.",
"public_repos": 27,
"public_gists": 19,
"followers": 28,
"following": 83,
"created_at": "2017-07-04T14:21:16Z",
"updated_at": "2019-09-19T14:43:57Z"
}
</code></pre>
</section>
<section style="text-align: left;">
<p>The response was encoded in <b>JSON</b> which allows us to represent <b>JavaScript Objects</b> in plain text.</p>
<p>The process of converting an object into JSON and back again to an object on the client is called <b>serialization</b>.</p>
</section>
<section style="text-align: left;">
<h1>JSON conversion</h1>
<p>On a node server we may have an object:</p>
<pre><code class="hljs">
let obj = {a: 1, b: 2};
</code></pre>
<p>Now to conver it to JSON:</p>
<pre><code class="hljs">
let response = JSON.stringify(obj);
</code></pre>
<p>Then, we'll send this in the body of a HTTP response</p>
</section>
<section style="text-align: left;">
<p>Now the client has received the response.</p>
<p>To parse this string, we simpy use the built in method:</p>
<pre><code class="hljs">
let obj = JSON.parse(response_body);
</code></pre>
<p>What we have just done is deconstruct and reconstruct a JavaScript object from a server to a client.</p>
</section>
</div>
</div>
<script src="reveal/js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
center: true,
hash: true,
transition: "slide", // none/fade/slide/convex/concave/zoom
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{
src: "reveal/plugin/markdown/marked.js",
condition: function() {
return !!document.querySelector("[data-markdown]");
}
},
{
src: "reveal/plugin/markdown/markdown.js",
condition: function() {
return !!document.querySelector("[data-markdown]");
}
},
{ src: "reveal/plugin/highlight/highlight.js", async: true },
{ src: "reveal/plugin/search/search.js", async: true },
{ src: "reveal/plugin/zoom-js/zoom.js", async: true },
{ src: "reveal/plugin/notes/notes.js", async: true }
]
});
</script>
</body>
</html>