-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.oal
82 lines (67 loc) · 2.3 KB
/
main.oal
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
/*
* Example of OAL definition for the Restbucks imaginary coffee shop
* https://www.infoq.com/articles/webber-rest-workflow/
*/
# title: drink
let drink = str `enum: [espresso, latte]`;
# title: addition to a drink
let addition = str `enum: [shot]`;
# title: status of an order
let orderStatus = str `enum: [created, preparing, ready]`;
# title: credit card number
let cardNo = str `pattern: "^[0-9]{16}$", example: 4470826293333986`;
# title: credit card expiration month and year
let cardExpiration = str `pattern: "^[0-9]{2}/[0-9]{2}$", example: 10/25`;
# title: price
let price = num `example: 4.45`;
# title: drink order
let @order = {
'drink! drink,
'additions [addition],
'cost price,
'status orderStatus,
};
# title: payment
let @payment = {
'cardNo! cardNo,
'expires! cardExpiration,
'name! str,
'amount! price,
};
// Resource URIs
let id = 'id int `title: internal identifier`;
let uriOrders = /orders;
let uriOrder = concat uriOrders /{ id };
let uriPayment = /payments/{ id };
// Helper functions for operation results
let created u s = <status=201, headers={ 'Location u }, s> `description: Created`;
let ok u s = <status=200, headers={ 'Location u }, s> `description: OK`;
let conflict u s = <status=409, headers={ 'Location u }, s> `description: Conflict`;
# title: order resource representation
let resOrder = @order & {
'payment relPayment,
'edit relOrder,
};
# title: order relation
let relOrder = uriOrder on
# description: Update an order
( put : { 'order! @order } -> ok relOrder { 'order! resOrder }
:: conflict relOrder { 'order! resOrder } ),
# description: Delete an order
( delete -> <status=200> `description: Deleted` );
# title: orders collection relation
let relOrders = uriOrders on
# description: Create an order
( post : { 'order! @order } -> created relOrder { 'order! resOrder } ),
# description: Retrieve all orders
( get -> ok relOrders { 'orders! [resOrder] } );
# title: payment relation
let relPayment = uriPayment on
# description: Make a payment
( put : { 'payment! @payment } -> created relPayment { 'payment! @payment } ),
# description: Retrieve a payment
( get -> ok relPayment { 'payment! @payment } );
// All exported relations
res relOrders;
res relOrder;
res relPayment;