-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
45 lines (33 loc) · 827 Bytes
/
app.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
require 'bundler'
require 'json'
Bundler.require
Loader.autoload
class App < Rack::App
mount SomeAppClass
headers 'Access-Control-Allow-Origin' => '*',
'Access-Control-Expose-Headers' => 'X-My-Custom-Header, X-Another-Custom-Header'
serializer do |object|
object.to_s
end
desc 'some hello endpoint'
get '/hello' do
'Hello World!'
end
desc 'some restful endpoint'
get '/users/:user_id' do
response.status = 201
params['user_id'] #=> restful parameter :user_id
say #=> "hello world!"
end
desc 'some endpoint that has error and will be rescued'
get '/make_error' do
raise(StandardError,'error block rescued')
end
def say
"hello #{params['user_id']}!"
end
error StandardError, NoMethodError do |ex|
{:error=>ex.message}
end
root '/hello'
end