Sinatra is a lightweight web framework. Sinatra is similar to Ruby on Rails web frameworks. It’s pretty different from Rails as it’s much lighter (less overhead), and you have more fine-grained control over your web app. Additionally, there is no built-in database functionality or page rendering — all of that is done manually. So it is more popular among millennials as you can bend it like the way you need.

Contents

Sinatra Introduction

Unlike Ruby on Rails, which is a Full Stack Web Development Framework that provides everything needed from front to back, Sinatra is fast, simple and efficient. However, with that comes more work and more room for error. Sinatra is best used for smaller web applications or ones that don’t need bloat, like those on the list on their website. Single-purpose apps abound, like one that only flips text upside down.

Pre-requisite system

Installation steps

You can install Sinatra like any other gem

gem install sinatra

And you have successfully installed sinatra web framework.

Getting started: Hello World With Sinatra Web Framework

Now you have already for your first app

let’s create a folder named Hello_world

mkdir Hello_world

now we can create a file let’s say hello.rb

cd booklist touch hello.rb

and place our hello world code into our newly created hello.rb file

# hello.rb
require 'sinatra'

get '/' do
  'Hello World!'
end

now you can start the server and test your application

get inside your hello_world project and run

ruby server.rb

Check out the result at http://localhost:4567

The code you changed will not take effect until you restart the server. Please restart the server every time you change or use sinatra/reloader.

Hope you have enjoyed reading on how to start on Hello World With Sinatra Web Framework. We recommend Sinatra’s own Getting Started guide.

One Response