Examples

Complete servers live in examples/ in the repo. From a checkout:

bundle install
bundle exec ruby examples/puma.rb
bundle exec ruby examples/falcon.rb

The Sinatra and Grape examples need their adapter gems, which live in separate bundles (their dependencies conflict), so run them through those gemfiles:

BUNDLE_GEMFILE=gemfiles/sinatra.gemfile bundle exec ruby examples/sinatra.rb
BUNDLE_GEMFILE=gemfiles/grape.gemfile   bundle exec ruby examples/grape.rb

All of them listen on http://127.0.0.1:9292.

Router on puma

require "ratalada/puma"

Server.run do |request|
  case request
  in ["GET", "/"]      then "hello from puma\n"
  in ["GET", "/up"]    then "ok\n"
  in ["POST", "/echo"] then ->(req) { [200, { "content-type" => "text/plain" }, req.body] }
  end
end
curl http://localhost:9292/
curl -d "hello" http://localhost:9292/echo

Router on falcon

require "ratalada/falcon"

Server.run do |request|
  case request
  in ["GET", "/"]      then "hello from falcon\n"
  in ["GET", "/up"]    then "ok\n"
  in ["GET", "/greet"] then ->(req) { "hello #{req.query.delete_prefix("name=")}\n" }
  end
end
curl "http://localhost:9292/greet?name=world"

Sinatra on falcon

require "ratalada/falcon"
require "ratalada/sinatra"

Server.run do
  get "/" do
    "hello from sinatra on falcon\n"
  end

  get "/greet/:name" do
    "hello #{params[:name]}\n"
  end
end
curl http://localhost:9292/greet/world

Grape on falcon

require "ratalada/falcon"
require "ratalada/grape"

Server.run do
  format :txt

  get "/" do
    "hello from grape on falcon\n"
  end

  get "/greet/:name" do
    "hello #{params[:name]}\n"
  end
end
curl http://localhost:9292/greet/world

This site uses Just the Docs, a documentation theme for Jekyll.