-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams.rb
More file actions
51 lines (41 loc) · 869 Bytes
/
params.rb
File metadata and controls
51 lines (41 loc) · 869 Bytes
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
require 'sinatra'
# require 'pry-byebug'
@@result= []
# CRUD
# root route
get '/' do
puts "I'm visible in the terminal"
"I'm visible in the browser"
end
# /names/:id
get '/names/:id' do
result = nil
if params[:id].is_a? Numeric
names = ["Fernando", "Inez", "Claudia", "Magda"]
id = params[:id].to_i
result = names[id]
else
result = 400
end
result
end
# Whatever number the user gives, is stored in an array.
# This should return the whole array once the number was stored.
# This should accept anything, even words.
post '/store/:id' do
id = params[:id]
unless (id.is_a? Numeric) || (id.is_a? String)
@@result = 400
else
@@result << id
end
@@result
end
# Update
put '/put_route' do
"I put it"
end
# Delete
delete '/delete_route' do
"I deleted it"
end