Skip to content

Releases: tbrand/router.cr

Simple rendering fucntion

01 Apr 15:56
Compare
Choose a tag to compare

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

30 Mar 15:01
Compare
Choose a tag to compare

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)

29 Mar 11:59
Compare
Choose a tag to compare

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

27 Mar 13:43
Compare
Choose a tag to compare
  • 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

26 Mar 07:33
Compare
Choose a tag to compare

Bug fixes especially for UriParams.

First release!!

25 Mar 14:53
Compare
Choose a tag to compare

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