http-multiserver.cr alternatives and similar shards
Based on the "HTTP" category.
Alternatively, view http-multiserver.cr alternatives based on common mentions on social networks and blogs.
-
route.cr
Minimum High Performance Middleware for Crystal Web Server. -
halite
๐HTTP Requests Client with a chainable REST API, built-in sessions and middlewares. -
Cable
It's like ActionCable (100% compatible with JS Client), but you know, for Crystal -
cossack
Simple and flexible HTTP client for Crystal with middleware and test support. -
http-protection
This library protects against typical web attacks. It was inspired in rack-protection Ruby gem. -
helmet
a port of the Node Helmet module to the Crystal programming language -
crystal-routing
Extensible library to deal with http request and string based routing in Crystal -
http-params-serializable
The HTTP params parsing module for Crystal ๐ค -
http_parser.cr
Crystal wrapper for Http Parser lib: https://github.com/joyent/http-parser -
multipart.cr
Adds multipart and multipart/form-data support to the crystal standard library -
proxy-fetcher.cr
Crystal port of awesome Ruby ProxyFetcher gem -
ContentDisposition
Crystal shard to create HTTP Content-Disposition headers with proper escaping/encoding of filenames -
http_distributor
http server which allows sneaky http request though it. -
router-simple.cr
simple path router inspired by Router::Simple. -
crystal-cossack
Simple and flexible HTTP client for Crystal with middleware and test support.
Clean code begins in your IDE with SonarLint
Do you think we are missing an alternative of http-multiserver.cr or a related project?
README
HTTP::Multiserver
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
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
- Fork it ( https://github.com/vladfaust/http-multiserver.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- @vladfaust Vlad Faust - creator, maintainer