Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple Sinatra app with a counter using in-memory state and route handlers.
require 'sinatra'
count = 0
get '/counter' do
"<h2>Counter: #{count}</h2>
<form method='post' action='/increment'>
<button type='submit'>+</button>
</form>
<form method='post' action='/decrement'>
<button type='submit'>-</button>
</form>
<form method='post' action='/reset'>
<button type='submit'>Reset</button>
</form>"
end
post '/increment' do
count += 1
redirect '/counter'
end
post '/decrement' do
count -= 1
redirect '/counter'
end
post '/reset' do
count = 0
redirect '/counter'
end
# Run with: ruby app.rb -p 4567Sinatra is a lightweight, domain-specific Ruby web framework for quickly creating web applications and APIs with minimal boilerplate, emphasizing simplicity and flexibility.
Origin & Creator
Created by Blake Mizerany in 2007 as a minimal Ruby web framework alternative to Rails.
Industrial Note
Widely used in lightweight web services, microservices, RESTful APIs, and quick prototypes, often in startups or for internal tooling.