forked from byteclubfr/js-hal
-
Notifications
You must be signed in to change notification settings - Fork 3
/
sample.js
30 lines (24 loc) · 849 Bytes
/
sample.js
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
var hal = require('./');
var ordersCollection = new hal.Resource({
currentlyProcessing: 14,
shippedToday: 20
}, "/orders");
ordersCollection.link("next", "/orders?page=2");
ordersCollection.link("find", {href: "/orders{?id}", templated: true});
var order123 = new hal.Resource({
total: 30.00,
currency: "USD",
status: "shipped"
}, "/orders/123");
order123.link(new hal.Link("basket", "/baskets/98712"));
order123.link(new hal.Link("customer", {href: "/customers/7809"}));
var order124 = new hal.Resource({
total: 20.00,
currency: "USD",
status: "processing"
}, "/orders/124");
order124.link("basket", "/baskets/97213");
order124.link("customer", "/customers/12369");
ordersCollection.embed("orders", [order123, order124]);
console.log('JSON:', ordersCollection.toJSON(' '));
console.log('XML:', ordersCollection.toXML(' '));