Backend Technologies · Ruby
Sinatra — Free Learning Resources
Free, printable resources for Sinatra — practice problems, quick-reference cheatsheet, and an interview prep sheet. No sign-up required.
Sinatra — Practice Worksheet
Structured exercises and problems to build hands-on Sinatra skills. Work through key concepts step by step.
Sinatra — Cheatsheet
One-page quick-reference for Sinatra — key syntax, commands, patterns, and best practices at a glance.
Sinatra — Interview Sheet
Top Sinatra interview questions with concise answers. Get ready for any technical round with this focused prep sheet.
About Sinatra
Sinatra is a minimal Ruby web framework (DSL) for building web applications and APIs quickly. Its simple, expressive route definitions make it ideal for small services, rapid prototyping, and learning web fundamentals — without Rails' conventions and overhead.
SinatraCheat Sheet — What's Covered
- ✓Route definitions — get, post, put, patch, delete with block handlers
- ✓Request and response — params, request object, and status/headers
- ✓ERB templating, static files, and before/after filters
- ✓Modular vs. classic application style
- ✓Deployment with Rack and Puma/Thin
Frequently Asked Questions — Sinatra
How does Sinatra routing work?
Routes are method + URL pattern + block: get '/users/:id' { User.find(params[:id]).to_json }. Patterns support named params (:id), splats (*), and regex. Routes are matched in definition order — first match wins.
What is the difference between classic and modular Sinatra style?
Classic style: require 'sinatra' and define routes at the top level — quick for scripts. Modular style: class App < Sinatra::Base — needed for mounting multiple apps, testing, and larger codebases. Modular is recommended for anything beyond a prototype.
How do you use before and after filters in Sinatra?
before { @user = authenticate! } runs before every route. before '/admin/*' {} scopes to a URL pattern. after {} runs after the route handler. Use them for authentication, logging, and setting common instance variables.
How does Sinatra handle JSON APIs?
Set content_type :json and return obj.to_json from routes. Use the sinatra-json helper or enable :json in settings. Parse incoming JSON with JSON.parse(request.body.read). For validation and serialization, add ActiveModel or dry-rb.
How do you test Sinatra apps?
Sinatra integrates with Rack::Test — include it in RSpec or Minitest. Use get '/path', {}, {'HTTP_AUTHORIZATION': ...} to make requests and assert on last_response.status and JSON.parse(last_response.body). No server needed.
Who Is This For?
Ruby developers building small APIs, microservices, or prototypes who want a lightweight alternative to Rails with minimal setup.