Adding other routes

Let’s say we want to add a little more interaction to our server. To do this we’ll want to be able to respond to more than just requests for the root URL. And sinatra let’s you do that. In your program you can add as many routes as you like.

Try it by adding the following to your app.rb and save your file


get '/about' do
  'A little about me.'
end

This should add a new endpoint to our server that maps to http://localhost:4567/about. If the ‘/about’ URL is requested (using the GET HTTP method), “A little about me.” will display.

×

Subscribe

The latest tutorials sent straight to your inbox.