-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_server.tex
141 lines (127 loc) · 3.29 KB
/
rest_server.tex
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
\section{REST in Rails}
\imageFrame{images/rest-in-rails.jpg}
\centeredFrame{REST in Rails}
\centeredFrame{in Rails it's easier to build RESTful\\than non-RESTful apps}
\centeredFrame{quick demo}
% create Rails app, scaffold posts, turn off forgery protection
% curl -X POST -H 'Accept: application/xml' -d post[title]='test' -d post[body]='test' http://localhost:3000/posts
% curl -X GET -H 'Accept: application/xml' http://localhost:3000/posts/x
% curl -X PUT -H 'Accept: application/xml' -d post[title]='updated with curl' http://localhost:3000/posts/x
% curl -X GET -H 'Accept: application/xml' http://localhost:3000/posts/x
% curl -X DELETE -H 'Accept: application/xml' http://localhost:3000/posts/x
\centeredFrame{how does it work?}
\begin{frame}
\frametitle{\insertsection}
\begin{columns}
\begin{column}{3cm}
\begin{center}REST actions\\\end{center}
POST\\
GET\\
PUT\\
DELETE
\end{column}
\end{columns}
\end{frame}
\begin{frame}
\frametitle{\insertsection}
\begin{columns}
\begin{column}{3cm}
\begin{center}Rails actions\\\end{center}
create\\
show\\
update\\
destroy\\
\uncover<2->{new\\}
\uncover<2->{edit\\}
\uncover<2->{index\\}
\end{column}
\end{columns}
\end{frame}
\centeredFrame{7 default actions}
\begin{frame}
\frametitle{\insertsection}
\begin{columns}
\begin{column}{2.5cm}
\begin{center}Rails actions\\\end{center}
create\\
show\\
update\\
destroy\\
index\\
new\\
edit
\end{column}
\begin{column}{3.5cm}
\begin{center}HTTP request\\\end{center}
\begin{columns}
\begin{column}{1.5cm}
POST\\
GET\\
PUT\\
DELETE\\
GET\\
GET\\
GET
\end{column}
\begin{column}{2cm}
/users\\
/users/1\\
/users/1\\
/users/1\\
/users\\
/users/1/new\\
/users/1/edit
\end{column}
\end{columns}
\end{column}
\end{columns}
\end{frame}
\centeredFrame{how does Rails know how to map URI to an action?}
\centeredFrame{routes}
\inputFrame{config/routes.rb}{}{files/routes}
\centeredFrame{
generates mapping for 7 default actions\\
for user resource
}
\centeredFrame{
generates helper methods for 7 default actions\\
for user resource
}
\begin{frame}
\frametitle{\insertsection}
\begin{columns}
\begin{column}{2cm}
\begin{center}Rails actions\end{center}
create\\
show\\
update\\
destroy\\
index\\
new\\
edit
\end{column}
\begin{column}{2cm}
\begin{center}URI\end{center}
/users\\
/users/1\\
/users/1\\
/users/1\\
/users\\
/users/1/new\\
/users/1/edit
\end{column}
\begin{column}{2cm}
\begin{center}helpers\end{center}
users\_path\\
user\_path(1)\\
user\_path(1)\\
user\_path(1)\\
users\_path\\
new\_user\_path\\
edit\_user\_path(1)
\end{column}
\end{columns}
\end{frame}
\centeredFrame{resource representations}
\centeredFrame{respond\_to}
\inputFrame{app/controllers/users\_controller.rb}{\small}{files/respond-to}