All Projects → vladfaust → http-multiserver.cr

vladfaust / http-multiserver.cr

Licence: MIT license
Mount multiple web applications 🚦

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to http-multiserver.cr

Router
⚡️ A lightning fast HTTP router
Stars: ✭ 158 (+586.96%)
Mutual labels:  router, handler
Lion
Lion is a fast HTTP router for building modern scalable modular REST APIs in Go
Stars: ✭ 750 (+3160.87%)
Mutual labels:  router, handler
Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (+639.13%)
Mutual labels:  router, handler
Dotweb
Simple and easy go web micro framework
Stars: ✭ 1,354 (+5786.96%)
Mutual labels:  router, handler
Easyrouter
A component routing framework simple, stable and high-performance, which supports UI, Method Calls, Interceptors, Callbacks and More than these.
Stars: ✭ 172 (+647.83%)
Mutual labels:  router, dispatcher
easytcp
✨ 🚀 EasyTCP is a light-weight TCP framework written in Go (Golang), built with message router. EasyTCP helps you build a TCP server easily fast and less painful.
Stars: ✭ 416 (+1708.7%)
Mutual labels:  router
Stime
基于Vue-cli3(Vue+Vue-router)构建的单页单栏Typecho主题,全站Ajax+类Pjax(Vue-router)无刷新,自适应适配移动设备
Stars: ✭ 29 (+26.09%)
Mutual labels:  router
es6-router
🌐 Simple client side router built in ES6
Stars: ✭ 16 (-30.43%)
Mutual labels:  router
tulingx
TULINGX(图灵)VPN下载页 翻墙 代理 科学上网 外网 加速器 梯子 路由
Stars: ✭ 59 (+156.52%)
Mutual labels:  router
neteng-roadmap
Network Engineering at Scale Roadmap/Landscape
Stars: ✭ 53 (+130.43%)
Mutual labels:  router
use-react-router-breadcrumbs
tiny, flexible, hook for rendering route breadcrumbs with react-router v6
Stars: ✭ 170 (+639.13%)
Mutual labels:  router
qlevar router
Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
Stars: ✭ 51 (+121.74%)
Mutual labels:  router
journey
A conductor routing helper library
Stars: ✭ 35 (+52.17%)
Mutual labels:  router
Android-XRouter
This is a lightweight and simple routing framework that provides jump routing and method routing.
Stars: ✭ 19 (-17.39%)
Mutual labels:  router
RoundedLayout
This is a library that has a rounded cut of View, support whether the specified corners are cropped and add a custom Border, and add a shadow support from API 9, which is based on FrameLayout, that is, His Child can be any View, the current library or preview version, if you encounter problems in the process can submit issue or pr.
Stars: ✭ 24 (+4.35%)
Mutual labels:  router
jobor
支持秒级分布式定时任务系统, A high performance distributed task scheduling system, Support multi protocol scheduling tasks
Stars: ✭ 52 (+126.09%)
Mutual labels:  dispatcher
lura
Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
Stars: ✭ 5,159 (+22330.43%)
Mutual labels:  router
react-chicane
A simple and safe router for React and TypeScript.
Stars: ✭ 191 (+730.43%)
Mutual labels:  router
orion
A Crystal router
Stars: ✭ 115 (+400%)
Mutual labels:  router
routex.js
🔼 Alternative library to manage dynamic routes in Next.js
Stars: ✭ 38 (+65.22%)
Mutual labels:  router

HTTP::Multiserver

Built with Crystal Build status API Docs Releases Awesome vladfaust.com Patrons count Gitter chat

The requests dispatcher shard for Crystal.

Supporters

Thanks to all my patrons, I can continue working on beautiful Open Source Software! 🙏

Lauri Jutila, Alexander Maslov, Dainel Vera

You can become a patron too in exchange of prioritized support and other perks

Become Patron

About

HTTP::Multiserver dispatches a server request to another vanilla HTTP::Server depending on its path similar to Ruby's Rack::URLMap.

Installation

Add this to your application's shard.yml:

dependencies:
  http-multiserver:
    github: vladfaust/http-multiserver.cr
    version: ~> 0.2.0

This shard follows Semantic Versioning 2.0.0, so see releases and change the version accordingly.

Usage

Basic example

require "http-multiserver"

simple_server = HTTP::Server.new([HTTP::LogHandler.new]) do |context|
  context.response.print("Hello from Simple Server!")
end

# For example purposes
resque = Resque::Server.new

multiserver = HTTP::Multiserver.new({
  "/resque" => resque,
  "/"       => simple_server,
}, [HTTP::ErrorHandler.new(true)]) do |context|
  # This is an optional custom fallback handler; by default returns "404 Not Found"
  context.response.status_code = 418
  context.response.print("#{context.request.path} not found")
end

multiserver.bind_tcp(5000)
multiserver.listen

HTTP::Multiserver extends from a regular HTTP::Server, so it CAN have its own handlers. Same for underlying servers, they obviously CAN have their own handlers too.

Mapping

Mapping relies on either String or Regex keys; when using String as a key, a slash is automatically appended to it.

Assuming that this map is passed to HTTP::Multiserver initializer:

map = {
  "/foo"   => foo_server,
  %r{/bar} => bar_server,
  "/"      => fallback_server
}

multiserver = HTTP::Multiserver.new(port, map)

This is how the request is dispatched under the hood (simplified):

internal_map = {
  %r{^/foo/} => foo_server,
  %r{/bar}   => bar_server,
  %r{^/}     => fallback_server
}

path = request.path.append_slash # "/foo/abc" turns into "foo/abc/"
server = internal_map.find { |regex, _| regex.match(path) }
server ? server.call(context) : not_found

Please see specs for dispatching specifications.

Performance

As mentioned above, HTTP::Multiserver is just a regular HTTP::Server which dispatches the handling to underlying servers based on super-fast Regex.match. A very tiny impact on the performance is expected if any.

Contributing

  1. Fork it ( https://github.com/vladfaust/http-multiserver.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

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].