-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.rb
61 lines (47 loc) · 893 Bytes
/
server.rb
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
require 'sinatra'
require 'json'
before '/api*' do
content_type :json
end
get '/' do
@title = 'Index'
erb :index
end
get '/demo' do
@title = 'Demo'
erb :demo
end
get '/jquery_promise' do
@title = 'jQuery Promise'
erb :jquery_promise
end
get '/native_promise' do
@title = 'Native JavaScript Promise'
erb :native_promise
end
get '/basics' do
@title = 'Basics'
erb :basics
end
get '/api/order.json' do
items = [
{item: 'Cuddly Toy', price: 19.99},
{item: 'Fuzzy Sweater', price: 9.99},
{item: 'Hoverboard', price: 999.99}
]
sleep(1)
JSON.pretty_generate({
items: items,
order_total: items.reduce(0){ |sum, item|
sum + item[:price]
}
})
end
get '/api/shipping.json' do
sleep(1)
{shipping_charge: 12.34}.to_json
end
get '/api/taxes.json' do
sleep(1)
{local_taxes: 140.12}.to_json
end