0Pricing
Ruby Academy · Lesson

Sinatra Basics

Lightweight web apps.

What Is Sinatra?

Sinatra is a lightweight DSL for building web applications in Ruby with minimal effort.

  • No heavy conventions like Rails
  • Define routes directly in a single file
  • Perfect for small apps, APIs, and prototypes

You describe HTTP verbs and paths, and return a response body.

require 'sinatra'

get '/' do
  'Hello from Sinatra!'
end

Installing Sinatra

Sinatra is a gem. You install it with the gem command or via a Gemfile.

  • gem install sinatra
  • Or add gem 'sinatra' to a Gemfile and run bundle install

Run your app with ruby app.rb and it serves on port 4567 by default.

# Gemfile
source 'https://rubygems.org'
gem 'sinatra'
gem 'puma'

All lessons in this course

  1. Sinatra Basics
  2. Routes and Params
  3. JSON APIs
  4. Middleware and Rack
← Back to Ruby Academy