forked from bukalapak/snowboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02. Resource and Actions.html
418 lines (324 loc) · 13 KB
/
02. Resource and Actions.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<!DOCTYPE html>
<html lang="en">
<head>
<title>Resource and Actions API</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.4/semantic.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/themes/prism-okaidia.min.css" />
<style>
blockquote {
border-left: solid 4px #eee;
padding-left: 8px;
font-style: italic;
margin-left: 0;
padding: 8px;
}
.ui.micro.label {
font-size: .25rem;
}
.ui.transaction.accordion .title {
text-align: center;
}
.ui.transaction.accordion .content {
border-top: solid 1px #ddd !important;
border-bottom: solid 1px #ddd !important;
background-color: rgba(0,0,0,.03);
padding: 0.5em 1em !important;
}
.ui.transaction.accordion .content.active {
margin-top: 0.5em;
}
.ui.basic.label {
text-align: left;
overflow: auto;
}
.ui.basic.label.request-url {
user-select: text;
}
.resource .ui.sub.header {
text-transform: none;
}
@media only screen and (min-width: 768px) {
.sidewrap {
margin-right: 2rem;
}
.sidenav {
left: 0;
top: 0;
width: inherit;
position: fixed !important;
height: 100% !important;
overflow-y: auto !important;
padding-left: 0.5rem;
}
}
</style>
</head>
<body>
<div class="ui padded grid">
<div class="sidewrap four wide computer five wide tablet sixteen wide mobile column">
<div class="sidenav">
<div class="ui horizontal divider">
<a href="#introduction">Introduction</a>
</div>
<div class="ui fluid secondary vertical menu">
<a class="item" href="#introduction">Resource and Actions API</a>
</div>
<div class="ui accordion fluid">
<div class="title active">
<i class="dropdown icon"></i>
<strong>/message</strong>
</div>
<div class="content active">
<div class="ui fluid secondary vertical menu">
<a class="item green" href="#message-get">
<i class="ui green empty circular label"></i>
<span>GET</span>
</a>
<a class="item teal" href="#message-put">
<i class="ui teal empty circular label"></i>
<span>PUT</span>
</a>
</div>
</div>
</div>
</div>
</div>
<div class="eleven wide computer ten wide tablet sixteen wide mobile column">
<div class="ui hidden divider header"></div>
<h1 class="ui huge header" id="introduction">Resource and Actions API</h1>
<hr class="ui divider">
<div class="description">
<p>This API example demonstrates how to define a resource with multiple actions.</p>
<h2 id="api-blueprint">API Blueprint</h2>
<ul>
<li><p><a href="01.%20Simplest%20API.md">Previous: The Simplest API</a></p></li>
<li><p><a href="https://raw.github.com/apiaryio/api-blueprint/master/examples/02.%20Resource%20and%20Actions.md">This: Raw API Blueprint</a></p></li>
<li><p><a href="03.%20Named%20Resource%20and%20Actions.md">Next: Named Resource and Actions</a></p></li>
</ul>
</div>
<div class="ui hidden divider"></div>
<div class="ui horizontal divider" >
</div>
<div class="ui header center aligned">
<div class="ui header">
<div class="sub header">
</div>
</div>
</div>
<div class="ui stacked segments">
<div class="ui basic segment resource">
<div class="ui purple huge ribbon label">
/message
</div>
<div class="ui header">
<div class="ui sub header">
<p>This is our <a href="http://www.w3.org/TR/di-gloss/#def-resource">resource</a>. It is
defined by its
<a href="http://www.w3.org/TR/di-gloss/#def-uniform-resource-identifier">URI</a> or, more
precisely, by its <a href="http://tools.ietf.org/html/rfc6570">URI Template</a>.</p>
<p>This resource has no actions specified but we will fix that soon.</p>
</div>
</div>
</div>
<div class="ui grey horizontal small divider header">
<i class="ui grey micro circular label"></i>
<i class="ui pink micro circular label"></i>
<i class="ui grey micro circular label"></i>
</div>
<div class="ui basic segment">
<h3 class="ui block center aligned header" id="message-get">
GET
</h3>
<div class="description"><p>Here we define an action using the <code>GET</code> <a href="http://www.w3schools.com/tags/ref_httpmethods.asp">HTTP request method</a> for our resource <code>/message</code>.</p>
<p>As with every good action it should return a
<a href="http://www.w3.org/TR/di-gloss/#def-http-response">response</a>. A response always
bears a status code. Code 200 is great as it means all is green. Responding
with some data can be a great idea as well so let’s add a plain text message to
our response.</p>
</div>
<h4 class="ui horizontal divider">
REQUEST
</h4>
<div class="description"></div>
<div class="fluid ui large labeled button">
<div class="ui green large button">
<h3>GET</h3>
</div>
<a class="ui basic fluid request-url green label">
<code>/message</code>
</a>
</div>
<h4 class="ui horizontal divider">RESPONSE</h4>
<div class="description"></div>
<table class="ui celled definition table">
<thead>
<tr>
<th colspan="2">Headers</th>
</tr>
</thead>
<tbody>
<tr>
<td class="four wide">Content-Type</td>
<td><code>text/plain</code></td>
</tr>
</tbody>
</table>
<div class="ui stacked blue segment">
<div class="ui fluid transaction accordion">
<div class="title center aligned">
<a class="ui blue circular label">
200
</a>
<code>text/plain</code>
</div>
<div class="content tabbed">
<div class="ui top attached tabular menu">
<a data-tab="body" class="active item">BODY</a>
<a data-tab="schema" class="item">SCHEMA</a>
</div>
<div class="ui bottom attached active tab segment" data-tab="body">
<pre style="white-space: inherit">
<code class="language-">Hello World!
</code>
</pre>
</div>
<div class="ui bottom attached tab segment" data-tab="schema">
<pre style="white-space: inherit">
<code class="language-json"></code>
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="ui grey horizontal small divider header">
<i class="ui grey micro circular label"></i>
<i class="ui pink micro circular label"></i>
<i class="ui grey micro circular label"></i>
</div>
<div class="ui basic segment">
<h3 class="ui block center aligned header" id="message-put">
PUT
</h3>
<div class="description"><p>OK, let’s add another action. This time to put new data to our resource
(essentially an update action). We will need to send something in a
<a href="http://www.w3.org/TR/di-gloss/#def-http-request">request</a> and then send a
response back confirming the posting was a success (<em>HTTP Status Code 204 ~
Resource updated successfully, no content is returned</em>).</p>
</div>
<h4 class="ui horizontal divider">
REQUEST
</h4>
<div class="description"></div>
<div class="fluid ui large labeled button">
<div class="ui teal large button">
<h3>PUT</h3>
</div>
<a class="ui basic fluid request-url teal label">
<code>/message</code>
</a>
</div>
<table class="ui celled definition table">
<thead>
<tr>
<th colspan="2">Headers</th>
</tr>
</thead>
<tbody>
<tr>
<td class="four wide">Content-Type</td>
<td><code>text/plain</code></td>
</tr>
</tbody>
</table>
<div class="ui stacked segment">
<div class="ui fluid transaction accordion">
<div class="title">
<code>text/plain</code>
</div>
<div class="content tabbed">
<div class="ui top attached tabular menu">
<a data-tab="body" class="active item">BODY</a>
<a data-tab="schema" class="item">SCHEMA</a>
</div>
<div class="ui bottom attached active tab segment" data-tab="body">
<pre style="white-space: inherit">
<code class="language-">All your base are belong to us.
</code>
</pre>
</div>
<div class="ui bottom attached tab segment" data-tab="schema">
<pre style="white-space: inherit">
<code class="language-json"></code>
</pre>
</div>
</div>
</div>
</div>
<h4 class="ui horizontal divider">RESPONSE</h4>
<div class="description"></div>
<table class="ui celled definition table">
<thead>
<tr>
<th colspan="2">Headers</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="ui stacked blue segment">
<div class="ui fluid transaction accordion">
<div class="title center aligned">
<a class="ui blue circular label">
204
</a>
<code></code>
</div>
<div class="content tabbed">
<div class="ui top attached tabular menu">
<a data-tab="body" class="active item">BODY</a>
<a data-tab="schema" class="item">SCHEMA</a>
</div>
<div class="ui bottom attached active tab segment" data-tab="body">
<pre style="white-space: inherit">
<code class="language-"></code>
</pre>
</div>
<div class="ui bottom attached tab segment" data-tab="schema">
<pre style="white-space: inherit">
<code class="language-json"></code>
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui hidden divider"></div>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/components/accordion.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/components/tab.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/components/transition.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/components/popup.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.13.0/prism.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.13.0/components/prism-json.min.js"></script>
<script type="text/javascript">
$(function() {
$('.ui.accordion').accordion({ animateChildren: false, duration: 0 });
$('.content.tabbed').each(function(index) {
$('.ui.tabular .item', $(this)).tab({ context: $(this) });
});
$('.ui.vertical.menu').on('click', '.item', function() {
$('.ui.vertical.menu .item').removeClass('active');
$(this).addClass('active');
});
$('.ui.empty.circular.label').popup();
});
</script>
</body>
</html>