Releases: gokmen/yeager
v0.1.8 - Late Friday
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!"
endv0.1.7 - Friday
This release includes support for HTTP method OPTIONS which is a preflight request for some browsers and clients for any request.
v0.1.6 - Thursday
It's now possible to use multiple Yeager::App handlers;
require "yeager"
app1 = Yeager::App.new
app2 = Yeager::App.new
app1.get "/" do |req, res, continue|
res.send "1"
continue.call
end
app1.get "/" do |req, res, continue|
res.send "2"
continue.call
end
app1.get "/" do |req, res, continue|
res.send "3"
continue.call
end
app2.get "/" do |req, res|
res.send "4"
end
app2.get "/foo" do |req, res|
res.send "bar"
end
server = HTTP::Server.new("0.0.0.0", 3000, [
app1.handler,
app2.handler,
])
server.listenFor requesting to / on 0.0.0.0:3000 will end up with String 1234, where 1 and 2 will be printed by app1, and 3 and 4 by app2 respectively. Also a request to /foo will end up with bar result even though it's provided by app2. Where app1 will pass all requests which it can't handle to the next handler which is app2, and it has /foo route to handle.
v0.1.5 - Friday
This is the initial release of Yeager with Yeager::App included.
Yeager::Router supports following;
- Multiple result support for given paths;
for given*, /test/*routes, router will match both of them when/test/foogiven as an input - Parameter, optional parameters and glob support;
for given/:foo?route;- router will return
{ :path => "/:foo?", "foo" => "test" }for/testrequest - router will return
{ :path => "/:foo?", "foo" => nil }for/request
- router will return
Yeager::App on top of Yeager::Router provides Express.js like interface for your web applications;
An advanced Yeager::App example would be;
require "yeager"
# Create the app
app = Yeager::App.new
# Add a glob handler to call before everything else
# will print "A new visit!" for each request
app.get "*" do |req, res, continue|
puts "A new visit!"
continue.call
end
# Add GET handler for "/" to response back with "Hello world!"
app.get "/" do |req, res|
res.send "Hello world!"
end
# Add another GET handler for "/:user"
# which will render "Hello yeager!" for "/yeager" route
app.get "/:user" do |req, res|
res.send "Hello #{req.params["user"]}!"
end
# Add a POST handler for "/add" and return a `json`
# with status code 200
app.post "/add" do |req, res|
res.status(200).json({"Hello" => "world!"})
end
# Start the app on port 3000
app.listen 3000 do
print "Example app listening on 0.0.0.0:3000!"
end