Tutorial by Examples

In Sinatra, routing is how your app responds to requests, by the path of the request (e.g. /welcome) and by the HTTP verb used (e.g. GET or POST). The way a request is written is as follows: <http-verb> <path> do <code block to execute when this route is requested> end He...
When matching the path of a route, you can do it explicitly, matching only one path, like so: get "/hello" do return "Hello!" end You can also use a regular expression to match complex routes. Any route which matches the regular expression will run that code block. If m...
There are a number of available routing verbs in Sinatra, they correspond directly to http verbs get '/' do .. get some data, a view, json, etc .. end post '/' do .. create a resource .. end put '/' do .. replace a resource .. end patch '/' do .. change a resource .. end ...
Of course you can pass data to Sinatra routes, to accept data in your routes you can add route paremeters. You can then access a params hash: get '/hello/:name' do # matches "GET /hello/foo" and "GET /hello/bar" # params['name'] is 'foo' or 'bar' "Hello #{params['...

Page 1 of 1