Router.cr Versions Save

Minimum High Performance Middleware for Crystal Web Server.

v0.1.7

7 years ago

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

v0.1.5

7 years ago

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

v0.1.4

7 years ago

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.

v0.1.2

7 years ago
  • 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

v0.1.1

7 years ago

Bug fixes especially for UriParams.

v0.1.0

7 years ago

route.cr has been published! :tada: Please check sample for detail.