Sinatra is a lightweight web application framework created in Ruby, characterized by being simple and easy to use. This article introduces the installation method and basic usage of Sinatra.
Installation
First, to install Sinatra, execute the following command.
gem install sinatra
Basic Usage
Introducing how to create a simple web application using Sinatra. Save the following code in a file called app.rb.
require 'sinatra'
get '/' do
'Hello, world!'
end
This code creates a web application that displays the message “Hello, world!” using Sinatra.
Starting the Application
To start the application, execute the following command.
ruby app.rb -o 0.0.0.0
When you execute this command, Sinatra will wait for requests on port 4567 by default. When you access localhost:4567 in your browser, the message “Hello, world!” will be displayed.