All Projects → tbrand → Router.cr

tbrand / Router.cr

Licence: mit
Minimum High Performance Middleware for Crystal Web Server.

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to Router.cr

Restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 341 (+47.62%)
Mutual labels:  middleware, http-server, webserver
Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (-26.41%)
Mutual labels:  middleware, http-server, webserver
restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 380 (+64.5%)
Mutual labels:  middleware, webserver, http-server
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (-39.83%)
Mutual labels:  middleware, http-server, webserver
Jennet
A simple HTTP web framework written in Pony
Stars: ✭ 72 (-68.83%)
Mutual labels:  http-server, webserver
Nico
A HTTP2 web server for reverse proxy and single page application, automatically apply for ssl certificate, Zero-Configuration.
Stars: ✭ 43 (-81.39%)
Mutual labels:  http-server, webserver
Mux.jl
Middleware for Julia
Stars: ✭ 225 (-2.6%)
Mutual labels:  middleware, webserver
Twig
Twig - less is more's web server for golang
Stars: ✭ 98 (-57.58%)
Mutual labels:  middleware, webserver
Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (+247.19%)
Mutual labels:  http-server, webserver
Igropyr
a async http server base on libuv for Chez Scheme
Stars: ✭ 85 (-63.2%)
Mutual labels:  http-server, webserver
Octane
A web server modeled after express in Rust.
Stars: ✭ 136 (-41.13%)
Mutual labels:  http-server, webserver
Embedio
A tiny, cross-platform, module based web server for .NET
Stars: ✭ 1,007 (+335.93%)
Mutual labels:  http-server, webserver
Go Bootstrap
Easy way to bootstrap a web server in Go (Routing|Middleware|Https)
Stars: ✭ 27 (-88.31%)
Mutual labels:  middleware, http-server
Suave
Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.
Stars: ✭ 1,196 (+417.75%)
Mutual labels:  http-server, webserver
Webcpp
用C++开发web服务器框架
Stars: ✭ 23 (-90.04%)
Mutual labels:  http-server, webserver
Proxy.py
⚡⚡⚡Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging
Stars: ✭ 1,291 (+458.87%)
Mutual labels:  http-server, webserver
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+1352.38%)
Mutual labels:  http-server, webserver
Elli
Simple, robust and performant Erlang web server
Stars: ✭ 194 (-16.02%)
Mutual labels:  http-server, webserver
Hydra
后端一站式微服务框架,提供API、web、websocket,RPC、任务调度、消息消费服务器
Stars: ✭ 407 (+76.19%)
Mutual labels:  http-server, webserver
Iodine
iodine - HTTP / WebSockets Server for Ruby with Pub/Sub support
Stars: ✭ 720 (+211.69%)
Mutual labels:  http-server, webserver

Build Status GitHub tag


The default web server of the Crystal is quite good 😄 but it weak at routing 😢.
Kemal or other web frameworks written in Crystal are awesome 😄, but it's too fat for some purpose 😢.

router.cr is a minimum but High Performance middleware for Crystal web server.
See the amazing performance of router.cr here.🚀

Installation

Add this to your application's shard.yml:

dependencies:
  router:
    github: tbrand/router.cr

Usage

Basic usage

require "router"

Include Router to utilize router.cr.

class WebServer
  include Router
end

Define a method to draw all routes for your web server.

class WebServer
  include Router
  
  def draw_routes
    # Drawing routes HERE!
  end
end

In that method, call HTTP method name (downcase) like get or post with PATH and BLOCK where

  • PATH : String
  • BLOCK : block of HTTP::Server::Context, Hash(String, String) -> HTTP::Server::Context
class WebServer
  include Router

  def draw_routes
    get "/" do |context, params|
      context.response.print "Hello router.cr!"
      context
    end
  end
end

Here we've defined a GET route at root path (/) that just print out "Hello router.cr" when we get access. To activate (run) the route, just define run methods for your server with route_handler

class WebServer
  include Router
  
  def draw_routes
    get "/" do |context, params|
      context.response.print "Hello router.cr!"
      context
    end
  end
  
  def run
    server = HTTP::Server.new(route_handler)
    server.bind_tcp 8080
    server.listen
  end
end

Here route_handler is getter defined in Router. So you can call route_handler at anywhere in WebServer instance.

Finally, run your server.

web_server = WebServer.new
web_server.draw_routes
web_server.run

See sample and tips for details.

Path parameters

params is a Hash(String, String) that is used when you define a path parameters such as /user/:id (:id is a parameters). Here is an example.

class WebServer
  include Router

  def draw_routes
    get "/user/:id" do |context, params|
      context.response.print params["id"] # get :id in url from params
      context
    end
  end
end

See sample and tips for details.

Contributing

  1. Fork it ( https://github.com/tbrand/router.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • tbrand Taichiro Suzuki - creator, maintainer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].