Skip to content
This repository was archived by the owner on Apr 21, 2019. It is now read-only.

v0.1.8 - Late Friday

Latest
Compare
Choose a tag to compare
@gokmen gokmen released this 14 Oct 05:29
· 1 commit to master since this release
deeb21e

This version introduces use directive for Yeager::App which allows one to use generic handlers for all routes. Following example will enable CORS for all routes, currently use does not support custom paths.

require "../src/yeager"

app = Yeager::App.new

app.get "/" do |req, res|
  res.send "Hello world!"
end

app.post "/" do |_, res|
  res.status(200).json({"Hello" => "world!"})
end

app.get "/:name" do |req, res|
  res.send "Hello sub world! #{req.params["name"]}"
end

# Enable CORS
# Even though it's defined at the end this handler will be
# called before all the handlers. Multiple use handlers
# can be defined which will be called sequentially.
app.use do |req, res, continue|
  res.headers.add "Access-Control-Allow-Origin", "*"
  continue.call
end

# If you have a defined HTTP::Server already you can
# use app.handler after this point instead of running
# the server of the app.
app.listen 3000 do
  print "Example app listening on 0.0.0.0:3000!"
end