-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathapiary.apib
422 lines (347 loc) · 13.9 KB
/
apiary.apib
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
FORMAT: 1A
HOST: https://fast-food-fast-bobsar0.herokuapp.com/
# FastFoodFast
FastFoodFast is a simple restaurant API that allows a customers to view food items on the menu and place an order for food.
The user must be signed up/logged in to use the app.
## Create a User account [POST /auth/signup]
You may create an account on the site using this action. It takes a JSON object containing credentials that may be used to login.
A token is generated which can be used to access other endpoints.
+ username (required, string) - A unique username.
+ email (required, string) - A unique valid email address.
+ password (required, string) - A string of 6 characters or greater, that must contain a capital letter, a small letter, a number and a special character.
+ phone (optional, string) - A unique phone number.
+ address (optional, string) - A default address to which orders can be delivered.
+ Request (application/json)
{
"username": "Mma",
"email": "chioma@gmail.com",
"password": "Abc123!",
"phone": "01234567890",
"address": "Andela Epic Tower"
}
+ Response 201 (application/json)
{
"status": "success",
"statusCode": 201,
"message": "Signup successful",
"user": {
"email": "chioma@gmail.com",
"username": "mma",
"phone": "01234567890",
"createdDate": "2018-10-14T17:16:16.512Z",
"modifiedDate": "2018-10-14T17:16:16.512Z",
"userId": 1
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsInJvbGUiOiJ1c2VyIiwiaWF0IjoxNTM5NTM3Mzc2LCJleHAiOjE1Mzk3MTAxNzZ9.04sHL8COqvL19lM88WqvJcOESKRfepDgSBtjC5rVkKJ"
}
## Login [POST /auth/login]
You may log into the site using this action. It takes a JSON object containing username or email, and password used during signup.
A token is generated which can be used to access other endpoints.
+ usernameEmail (required, string) - The username or email address that was used to signup.
+ password (required, string) - The password that was used to signup.
+ Request (application/json)
{
"usernameEmail": "Mma",
"password": "Abc123!",
}
+ Response 200 (application/json)
{
"status": "success",
"statusCode": 200,
"message": "Login successful",
"user": {
"user": {
"email": "chioma@gmail.com",
"username": "mma",
"phone": "01234567890",
"createdDate": "2018-10-14T17:16:16.512Z",
"modifiedDate": "2018-10-14T17:16:16.512Z",
"userId": 1
}
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjQsInJvbGUiOiJhZG1pbiIsImlhdCI6MTUzOTU0MDA2NywiZXhwIjoxNTM5NzEyODY3fQ.AvFWUAqjIk5Xfq5P7ux2Dkt2M1yAB9m0M8awXCzaH5x"
}
# Group Orders
Resources related to orders in the API.
## Orders Collection [/orders]
An Order object has the following attributes:
+ name
+ quantity
+ price
+ status
+ created_date
+ modified_date
### Create a New Order [POST]
You may create your own order using this action. It takes a JSON
payload containing food item parameters as part of the request which can be of two forms:
For immediate purchase (buy-now) of a single food item
+ name (required, string) - The name of the food item.
+ quantity (required, number) - The quantity of the food item in the form of an integer.
+ address (required, string) - The address to which the order would be delivered.
+ phone (required, string) - The phone number via which the customer can be contacted.
For add-to-cart purchase of one or more food items
+ foodArray (required array[object]) - A collection of food items as objects with name(string) and quantity(integer) pair.
+ address (required, string) - The address to which the order would be delivered.
+ phone (required, string) - The phone number via which the customer can be contacted.
+ Request (application/json)
{
"name": "Chicken Paella",
"quantity": 3,
"address": "Somewhere",
"phone": "08123456789
}
+ Response 201 (application/json)
{
"status": "success",
"statusCode": 201,
"message": "Order created successfully",
"order": {
"orderid": 10,
"userid": 4,
"food": "CHICKEN PAELLA",
"quantity": 3,
"price": 15000,
"status": "NEW",
"created_date": "2018-10-14T21:04:29.624Z",
"modified_date": "2018-10-14T21:04:29.624Z",
"address": "Somewhere",
"phone": "08123456789,
}
}
+ Request (application/json)
{
"cartArray":
[
{
"name": "Steak dish",
"quantity": 2
},
{ "name":"whole chicken paella",
"quantity": 2
}
],
"address": "Andela",
"phone": "08123456789"
}
+ Response 201 (application/json)
{
"status": "success",
"statusCode": 201,
"message": "Order created successfully",
"order": {
"orderid": 48,
"userid": 4,
"food": [
{
"name": "STEAK DISH",
"quantity": 2
},
{
"name": "WHOLE CHICKEN PAELLA",
"quantity": 2
}
],
"quantity": 4,
"price": 12000,
"address": "Andela",
"phone": "08123456789",
"status": "NEW",
"created_date": "2018-10-22T13:22:33.042Z",
"modified_date": "2018-10-22T13:22:33.042Z"
}
}
### List All Orders [GET]
+ Response 200 (application/json)
{
"status": "success",
"statusCode": 200,
"message": "Orders retrieved successfully",
"data": {
"orders": [
{
"orderid": 10,
"userid": 4,
"name": "CHICKEN PAELLA",
"quantity": 3,
"price": 15000,
"status": "NEW",
"created_date": "2018-10-14T21:04:29.624Z",
"modified_date": "2018-10-14T21:04:29.624Z"
},
{
"orderid": 9,
"userid": 4,
"name": "BURGER",
"quantity": 2,
"price": 1600,
"status": "PROCESSING",
"created_date": "2018-10-14T20:52:24.962Z",
"modified_date": "2018-10-14T20:52:24.962Z"
},
{
"orderid": 8,
"userid": 10,
"name": "BURGER",
"quantity": 2,
"price": 1600,
"status": "COMPLETED",
"created_date": "2018-10-14T20:50:16.554Z",
"modified_date": "2018-10-14T20:50:16.554Z"
}
],
"totalOrders": 3
}
}
## Order [/orders/{orderId}]
+ Parameters
+ orderId (number) - ID of the Order in the form of an integer
### Get a specific Order [GET]
This resource has an action to retrieve the details of a specific order.
+ Response 200 (application/json)
{
"status": "success",
"statusCode": 200,
"message": "Order retrieved successfully",
"data": {
"orderid": 9,
"userid": 4,
"name": "BURGER",
"quantity": 2,
"price": 1600,
"status": "PROCESSING",
"created_date": "2018-10-14T20:52:24.962Z",
"modified_date": "2018-10-14T20:52:24.962Z"
}
}
### Update a specific Order [PUT]
This resource has an action to update the status of an order. It can only be accessed by an admin.
+ status (required, string) - The new status of the order. It could be either 'NEW', 'PROCESSING', 'CANCELLED' or 'COMPLETED
The JSON payload is as follows:
+ Request (application/json)
{
"status": "Cancelled",
}
+ Response 200 (application/json)
{
"status": "success",
"statusCode": 200,
"message": "Status updated successfully",
"order": {
"orderid": 10,
"userid": 4,
"name": "CHICKEN PAELLA",
"quantity": 3,
"price": 15000,
"status": "CANCELLED",
"created_date": "2018-10-14T21:04:29.624Z",
"modified_date": "2018-10-14T22:16:10.503Z"
}
}
## User Order History [/users/{userId}/orders]
+ Parameters
+ userId (number) - ID of the user in the form of an integer
### Get Order History [GET]
This resource has an action to get the order history for a particular user.
+ Response 200 (application/json)
{
"statusCode": 200,
"status": "success",
"message": "Orders retrieved successfully",
"orders": [
{
"orderid": 8,
"userid": 4,
"name": "BURGER",
"quantity": 2,
"price": 1600,
"status": "COMPLETE",
"created_date": "2018-10-14T20:50:16.554Z",
"modified_date": "2018-10-14T20:50:16.554Z"
},
{
"orderid": 10,
"userid": 4,
"name": "CHICKEN PAELLA",
"quantity": 3,
"price": 15000,
"status": "CANCELLED",
"created_date": "2018-10-14T21:04:29.624Z",
"modified_date": "2018-10-14T22:16:10.503Z"
}
]
}
## Menu [/menu]
This route can only be accessed by an admin.
### Create a New Food Option [POST]
An admin may add food option to the menu using this action. It takes a JSON
payload containing food item parameters as part of the request.
+ name (required, string) - The name of the food item.
+ price (required, number) - The price of the food item in the form of an integer.
+ genre (required, string) - The genre to which the food item belongs to.
+ img (rqquired, string) - A url for an image that depicts the food item, isAvailable, created_date, modified_date
A sample JSON payload request is shown below. The request returns a 201 status code, and a body containing the response.
+ Request (application/json)
{
"name": "Steak",
"price": 1000,
"genre": "snack",
"img": "https://images.unsplash.com/photo-1432139555190-58524dae6a55?ixlib=rb-0.3.5&s=5f4049825eacb1b9e58bb76188fba497&auto=format&fit=crop&w=755&q=80",
}
+ Response 201 (application/json)
{
"status": "success",
"statusCode": 201,
"message": "New menu item added successfully",
"product": {
"productid": 3,
"name": "STEAK",
"price": 1000,
"genre": "snack",
"img": "https://images.unsplash.com/photo-1432139555190-58524dae6a55?ixlib=rb-0.3.5&s=5f4049825eacb1b9e58bb76188fba497&auto=format&fit=crop&w=755&q=80",
"isavailable": true,
"created_date": "2018-10-15T01:15:15.532Z",
"modified_date": "2018-10-15T01:15:15.532Z"
}
}
### List All Menu Items [GET]
This action allows to view all food items on the menu.
+ Response 200 (application/json)
{
"status": "success",
"statusCode": 200,
"message": "Orders retrieved successfully",
"data": {
"orders": [
{
"orderid": 10,
"userid": 4,
"name": "CHICKEN PAELLA",
"quantity": 3,
"price": 15000,
"status": "NEW",
"created_date": "2018-10-14T21:04:29.624Z",
"modified_date": "2018-10-14T21:04:29.624Z"
},
{
"orderid": 9,
"userid": 4,
"name": "BURGER",
"quantity": 2,
"price": 1600,
"status": "PROCESSING",
"created_date": "2018-10-14T20:52:24.962Z",
"modified_date": "2018-10-14T20:52:24.962Z"
},
{
"orderid": 8,
"userid": 10,
"name": "BURGER",
"quantity": 2,
"price": 1600,
"status": "COMPLETED",
"created_date": "2018-10-14T20:50:16.554Z",
"modified_date": "2018-10-14T20:50:16.554Z"
}
],
"totalOrders": 3
}
}