-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.ru
75 lines (58 loc) · 1.08 KB
/
app.ru
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
class ExampleApp < Eldr::App
class NotFound < StandardError
def call(env)
[404, {}, ['']]
end
end
attr_accessor :cats
before :before do
@thing1 = "Thing1"
end
before do
@thing2 = "Thing2"
end
after :cats do
@cats == 'Cats!'
end
get '/posts' do
Rack::Response.new "posts", 200
end
post '/posts' do
Rack::Response.new "posts", 201
end
put '/posts' do
Rack::Response.new "posts", 200
end
delete '/posts' do
Rack::Response.new "posts", 201
end
get '/deferred' do
throw :pass
end
get '/deferred' do
Rack::Response.new "Deferred!", 200
end
get '/raises-an-error' do
raise NotFound, 'Not Found'
end
get '/state' do
@state = 1 + @state.to_i
[200, {}, [@state]]
end
get '/state-2' do
[200, {}, [@state ||= 0]]
end
get '/before', name: :before do
[200, {}, [@thing1]]
end
get '/before-all', name: :before do
[200, {}, [@thing2]]
end
get '/after' do
[200, {}, ["Cats!"]]
end
get '/posts/:id' do
[200, {}, [params['id']]]
end
end
run ExampleApp