All Projects → marad → Hyper Router

marad / Hyper Router

Simple routing middleware for rust HTTP library hyper.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Hyper Router

Routerify
A lightweight, idiomatic, composable and modular router implementation with middleware support for the Rust HTTP library hyper.rs
Stars: ✭ 173 (+239.22%)
Mutual labels:  hyper, router
Hyper Hide Title
Hide the Hyper window title when there is only one tab
Stars: ✭ 46 (-9.8%)
Mutual labels:  hyper
React Starter
React Starter repository: cache bursting, css extraction, production, hot, react, redux, router, babel, eslint, jsx, webpack 3, editorconfig
Stars: ✭ 33 (-35.29%)
Mutual labels:  router
Vanilla Ui Router
Simple vanilla JavaScript router
Stars: ✭ 42 (-17.65%)
Mutual labels:  router
Copper
Copper is a set of Go packages that help you build backend APIs quickly and with less boilerplate.
Stars: ✭ 35 (-31.37%)
Mutual labels:  router
Esper
📻 Event Source powered by hyper written in Rust
Stars: ✭ 43 (-15.69%)
Mutual labels:  hyper
Khala
A URL Router for iOS/macOS, written in Swift
Stars: ✭ 31 (-39.22%)
Mutual labels:  router
Flowzard
Isolates navigation from UI and Business logic with simple wizard like mechanism.
Stars: ✭ 49 (-3.92%)
Mutual labels:  router
Restify Router
A router interface for restify that lets you aggregate route definitions and apply to a restify server
Stars: ✭ 45 (-11.76%)
Mutual labels:  router
Hyper
An HTTP library for Rust
Stars: ✭ 8,912 (+17374.51%)
Mutual labels:  hyper
Cve 2018 18852
CERIO RCE CVE-2018-18852, authenticated (vendor defaults) web-based RCE as root user.
Stars: ✭ 42 (-17.65%)
Mutual labels:  router
Redux Json Router
Declarative, Redux-first routing for React/Redux browser applications.
Stars: ✭ 37 (-27.45%)
Mutual labels:  router
Svelte Router
Simple Svelte Router for Single Page Applications (SPA).
Stars: ✭ 44 (-13.73%)
Mutual labels:  router
Altair
Lightweight and Robust API Gateway written in Go
Stars: ✭ 34 (-33.33%)
Mutual labels:  router
Webvr Webpack Boilerplate
A webvr multi-scenes Single-page application for three.js, webpack
Stars: ✭ 47 (-7.84%)
Mutual labels:  router
Angularconcepts
Key Angular Concepts using Latest Angular version 5
Stars: ✭ 31 (-39.22%)
Mutual labels:  router
Router
Stars: ✭ 41 (-19.61%)
Mutual labels:  router
Flouter
A router for Flutter based on Navigator 2.0 and Regexp
Stars: ✭ 43 (-15.69%)
Mutual labels:  router
Lantern
Lantern官方版本下载 蓝灯 翻墙 代理 科学上网 外网 加速器 梯子 路由 lantern proxy vpn censorship-circumvention censorship gfw accelerator
Stars: ✭ 10,238 (+19974.51%)
Mutual labels:  router
Ng Router Loader
Webpack loader for NgModule lazy loading using the angular router
Stars: ✭ 47 (-7.84%)
Mutual labels:  router

Hyper Router Build Status

This cargo is a small extension to the great Hyper HTTP library. It basically is adds the ability to define routes to request handlers and then query for the handlers by request path.

API Documentation

Usage

To use the library just add:

hyper = "^0.12"
hyper-router = "^0.5"

to your dependencies.

extern crate hyper;
extern crate hyper_router;

use hyper::header::{CONTENT_LENGTH, CONTENT_TYPE};
use hyper::{Request, Response, Body, Method};
use hyper::server::Server;
use hyper::rt::Future;
use hyper_router::{Route, RouterBuilder, RouterService};

fn basic_handler(_: Request<Body>) -> Response<Body> {
    let body = "Hello World";
    Response::builder()
        .header(CONTENT_LENGTH, body.len() as u64)
        .header(CONTENT_TYPE, "text/plain")
        .body(Body::from(body))
        .expect("Failed to construct the response")
}

fn router_service() -> Result<RouterService, std::io::Error> {
    let router = RouterBuilder::new()
        .add(Route::get("/greet").using(basic_handler))
        .build();

    Ok(RouterService::new(router))
}

fn main() {
    let addr = "0.0.0.0:8080".parse().unwrap();
    let server = Server::bind(&addr)
        .serve(router_service)
        .map_err(|e| eprintln!("server error: {}", e));

    hyper::rt::run(server)
}

This code will start Hyper server and add use router to find handlers for request. We create the Route so that when we visit path /greet the basic_handler handler will be called.

Things to note

  • you can specify paths as regular expressions so you can match every path you please.
  • If you have request matching multiple paths the one that was first added will be chosen.
  • This library is in an early stage of development so there may be breaking changes comming. - it seems that the library is quite popular so I'm not going to do compatibility breaking changes.

Further Development

  • add the ability to distinguish requests by query parameters.

Waiting for your feedback

I've created this little tool to help myself learn Rust and to avoid using big frameworks like Iron or rustful. I just want to keep things simple.

Obviously I could make some errors or bad design choices so I'm waiting for your feedback! Please contact me at moriturius at GMail. You may also create an issue at project's bug tracker.

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