All Projects → mjkillough → aitch

mjkillough / aitch

Licence: MIT License
aitch is a simple, lightweight toolkit for building HTTP servers in Rust, loosely based on Go's net/http.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to aitch

hyper-proxy
A proxy connector for Hyper-based crates
Stars: ✭ 73 (+284.21%)
Mutual labels:  hyper, tokio, futures
Tarpc
An RPC framework for Rust with a focus on ease of use.
Stars: ✭ 1,934 (+10078.95%)
Mutual labels:  tokio, futures
Tokio Rustls
Asynchronous TLS/SSL streams for Tokio using Rustls.
Stars: ✭ 143 (+652.63%)
Mutual labels:  tokio, futures
Tk Listen
A library that allows to listen network sockets with proper resource limits and error handling
Stars: ✭ 27 (+42.11%)
Mutual labels:  tokio, futures
Esper
📻 Event Source powered by hyper written in Rust
Stars: ✭ 43 (+126.32%)
Mutual labels:  hyper, http-server
Piping Server Rust
Infinitely transfer between any device over pure HTTP, designed for everyone using Unix pipe and even for browser users
Stars: ✭ 88 (+363.16%)
Mutual labels:  hyper, http-server
tsukuyomi
Asynchronous Web framework for Rust
Stars: ✭ 81 (+326.32%)
Mutual labels:  tokio, futures
hyper-reverse-proxy
A simple reverse proxy for use with Hyper and Tokio
Stars: ✭ 94 (+394.74%)
Mutual labels:  hyper, tokio
WebRelay
A netcat-like utility for windows for transferring files and streams over HTTP with support for relaying through a remote host (via websocket), a webclient, and a shell extension. PRs welcome!
Stars: ✭ 29 (+52.63%)
Mutual labels:  http-server
static-web-server
A blazing fast and asynchronous web server for static files-serving. ⚡
Stars: ✭ 230 (+1110.53%)
Mutual labels:  http-server
finch-demo
Introduction to Finch, a lightweight HTTP server library based on Twitter's Finagle.
Stars: ✭ 19 (+0%)
Mutual labels:  http-server
tokio-linux-aio
Support for Linux kernel aio within Tokio.
Stars: ✭ 49 (+157.89%)
Mutual labels:  tokio
httoop
HTTOOP - a fully object oriented HTTP protocol library written in python
Stars: ✭ 15 (-21.05%)
Mutual labels:  http-server
Kvpbase
Scalable, simple RESTful object storage platform, written in C#
Stars: ✭ 43 (+126.32%)
Mutual labels:  http-server
swoole-futures
⏳ Futures, Streams & Async/Await for PHP's Swoole asynchronous run-time.
Stars: ✭ 100 (+426.32%)
Mutual labels:  futures
oxen-storage-server
Storage server for Oxen Service Nodes
Stars: ✭ 19 (+0%)
Mutual labels:  http-server
ETAC
A one-page, Visual Canvas for Emerging Technology Evaluation, in the style of “the Business model Canvas".
Stars: ✭ 85 (+347.37%)
Mutual labels:  futures
tk-pool
A connection pool implementation for tokio
Stars: ✭ 20 (+5.26%)
Mutual labels:  tokio
malidate
A logging DNS and HTTP(S) server. Opensource alternative to some parts of the Burpsuite Collaborator server.
Stars: ✭ 31 (+63.16%)
Mutual labels:  http-server
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+1863.16%)
Mutual labels:  http-server

aitch Build Status Crates.io Docs.rs

aitch is a simple, lightweight toolkit for building HTTP servers in safe, stable Rust.

It builds upon the http crate, and provides additional types for representing HTTP handlers, bodies and middlewares. It provides both hyper and tiny_http backends for running handlers, but aims to be agnostic of the HTTP server library.

It's inspired by the simplicity (and popularity) of Go's net/http package, which builds application/middlewares as a series of nested Handlers.

aitch takes advantage of Rust's type system in order to make these handlers even easier to work with, without losing the simplicity that makes them so great.

Example

extern crate aitch;
extern crate http;

use aitch::servers::hyper::Server;
use aitch::{middlewares, Responder, Result};
use http::Request;

fn handler(_: Request<()>, mut resp: http::response::Builder) -> impl Responder {
    resp.body("Hello, world!".to_owned())
}

fn main() -> Result<()> {
    let wrapped = middlewares::with_stdout_logging(handler);

    let addr = "127.0.0.1:3000".parse()?;
    println!("Listening on http://{}", addr);
    Server::new(addr, wrapped)?.run()
}

This example is provided alongside aitch. To run it, clone this repository and run:

cargo run --release --example hello-world-sync

See also these other examples in the examples/ directory of this repo:

  • json.rs, which uses the optional Json<T> type to wrap structs which are automatically (de)serialized in request/response bodies.
  • simple-router.rs, which uses a simple request router, modelled after net/http's ServeMux.
  • shared-context.rs, which shows how to use the provided middlewares::with_context to inject a struct containing shared resources into an application's HTTP handlers.
  • examples/static-files.rs, which shows how to use the provided handlers::static_files::* handlers in order to serve static assets during development.

Dependencies & Features

aitch aims provide just the types necessary to build HTTP applications with your server technology of choice. It aims to be lightweight in both dependencies and runtime cost, while still being ergonomic to use.

To function, aitch requires a small number of dependencies: http, futures and bytes.

In order to help you be productive quickly, aitch provides a number of optional features, which are currently enabled by default:

  • server-hyper: Provides a Server, which can run an aitch::Handler using the hyper web server. (example)
  • server-tiny-http: Provides a Server, which can run an aitch::Handler using the tiny_http web server. (example)
  • json: Provides a Json<T> type, which can wrap any type T: serde::Deserialize + serde::Serialize, allowing it to be used in requests and responses: http::Request<Json<T>>/http::Response<Json<T>>. (example)
  • mime_guess: Uses the mime_guess crate to guess the MIME type of responses returned by the included handlers::static_files::* handlers.

These features will probably be split out into separate crates in the near future.

Is it fast?

It's pretty fast!

When profiling the default hello-world-sync example (with logging to stdout disabled, using Hyper), with 12 threads and 100 connections, we see ~130,000 req/s on a 2015 13inch MBP:

$ wrk --latency -t12 -c100 -d10s http://localhost:3000/
Running 10s test @ http://localhost:3000/
  12 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   837.87us    1.15ms  35.88ms   94.35%
    Req/Sec    11.09k     1.55k   17.44k    75.25%
  Latency Distribution
     50%  630.00us
     75%    1.06ms
     90%    1.61ms
     99%    3.45ms
  1325352 requests in 10.02s, 135.24MB read
Requests/sec: 132296.91
Transfer/sec:     13.50MB

License

MIT

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