Let's see how to write a bare minimum Sinatra application. We will open a new file and write the following code:
1 require 'sinatra' 2 get '/' do 3 return 'Hello World!' 4 end
Save the file with a
.rb extension (say,
helloworld.rb) and execute this on the command line:
$ ruby helloworld.rb
This will interpret the code and start the built-in server.
Now, we open the browser and point it to
What did the code do?
This tells the Ruby interpreter to load the Sinatra gem:
3 get '/' do 4 return 'Hello World!' 5 end
This forms a ruby code-block. Let's understand each line.
3. get '/' do
This block is invoked when the server receives a
get request on the
4. return 'Hello World!' ...