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!'
endInstalling 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 runbundle 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
- Sinatra Basics
- Routes and Params
- JSON APIs
- Middleware and Rack