Releases: tbrand/router.cr
Releases · tbrand/router.cr
Simple rendering fucntion
Added simple rendering functions to route.cr
Here is an example.
# Define view
def_view :user, "view/user.ecr", name: String
# Render it
@user = API.new |context|
context.response.print render_view(:user, "tbrand")
context
end
RouteHandler is now middleware
RouteHandler is now middleware.
class WebServer
include Route
@route_handler = RouteHandler.new
# GET "/"
@index = API.new do |context|
context.response.print "Hello route.cr"
context
end
def initialize
draw(@route_handler) do
get "/", @index
end
end
def run
server = HTTP::Server.new(3000, @route_handler)
server.listen
end
end
web_server = WebServer.new
web_server.run
Change core API (including breaking changes)
Check the breaking changes in README.md.
Here is a new sample of route.cr.
index = API.new do |context|
context.response.print "Hello Route.cr!"
context
end
get "/", index
server = HTTP::Server.new(3000, routeHandler)
server.listen
Also spawn_server is deprecated.
spawn_server: run multiple servers concurrently
- Add
spawn_server
macro, run multiple servers concurrently by using fiber threads. Just start listening a server like this.
# Running server in 4 threads concurrently
spawn_server(4) do
# Using default Crystal server
server = HTTP::Server.new(3000) do |context|
# Just call 'routing' method with the server context
# 'routing' returns nil if the route not found
routing(context)
end
# You have to reuse the port
# when you run multiple servers at same port
server.listen(true)
end
Bug fixes
First release!!
route.cr has been published! 🎉
Please check sample for detail.