{"id":19974639,"url":"https://github.com/mjkillough/aitch","last_synced_at":"2025-05-04T02:33:01.624Z","repository":{"id":57481634,"uuid":"122863756","full_name":"mjkillough/aitch","owner":"mjkillough","description":"aitch is a simple, lightweight toolkit for building HTTP servers in Rust, loosely based on Go's net/http.","archived":false,"fork":false,"pushed_at":"2018-07-21T22:36:59.000Z","size":136,"stargazers_count":18,"open_issues_count":4,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-13T08:40:01.043Z","etag":null,"topics":["async","futures","http","http-server","hyper","net-http","rust","tokio"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mjkillough.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-25T18:30:34.000Z","updated_at":"2024-06-07T23:32:27.000Z","dependencies_parsed_at":"2022-09-02T06:10:10.792Z","dependency_job_id":null,"html_url":"https://github.com/mjkillough/aitch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjkillough%2Faitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjkillough%2Faitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjkillough%2Faitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjkillough%2Faitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjkillough","download_url":"https://codeload.github.com/mjkillough/aitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224379812,"owners_count":17301525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","futures","http","http-server","hyper","net-http","rust","tokio"],"created_at":"2024-11-13T03:15:39.387Z","updated_at":"2024-11-13T03:15:39.961Z","avatar_url":"https://github.com/mjkillough.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aitch [![Build Status](https://travis-ci.org/mjkillough/aitch.svg?branch=master)](https://travis-ci.org/mjkillough/aitch) [![Crates.io](https://img.shields.io/crates/v/aitch.svg)](https://crates.io/crates/aitch) [![Docs.rs](https://docs.rs/aitch/badge.svg)](https://docs.rs/aitch/)\n\naitch is a simple, lightweight toolkit for building HTTP servers in safe, stable Rust.\n\nIt builds upon the [`http` crate](https://github.com/hyperium/http), and provides additional types for representing HTTP handlers, bodies and middlewares. It provides both [`hyper`](https://hyper.rs/) and [`tiny_http`](https://github.com/tiny-http/tiny-http) backends for running handlers, but aims to be agnostic of the HTTP server library.\n\nIt's inspired by the simplicity (and popularity) of Go's [`net/http` package](https://golang.org/pkg/net/http/), which builds application/middlewares as a series of nested [`Handler`s](https://golang.org/pkg/net/http/#Handler).\n\naitch 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.\n\n## Example\n\n```rust\nextern crate aitch;\nextern crate http;\n\nuse aitch::servers::hyper::Server;\nuse aitch::{middlewares, Responder, Result};\nuse http::Request;\n\nfn handler(_: Request\u003c()\u003e, mut resp: http::response::Builder) -\u003e impl Responder {\n    resp.body(\"Hello, world!\".to_owned())\n}\n\nfn main() -\u003e Result\u003c()\u003e {\n    let wrapped = middlewares::with_stdout_logging(handler);\n\n    let addr = \"127.0.0.1:3000\".parse()?;\n    println!(\"Listening on http://{}\", addr);\n    Server::new(addr, wrapped)?.run()\n}\n```\n\nThis example is provided alongside aitch. To run it, clone this repository and run:\n\n```sh\ncargo run --release --example hello-world-sync\n```\n\nSee also these other examples in the `examples/` directory of this repo:\n - [`json.rs`](examples/json.rs), which uses the optional `Json\u003cT\u003e` type to wrap structs which are automatically (de)serialized in request/response bodies.\n - [`simple-router.rs`](examples/simple-router.rs), which uses a simple request router, modelled after [`net/http`'s `ServeMux`](https://golang.org/pkg/net/http/#ServeMux).\n - [`shared-context.rs`](examples/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.\n - [`examples/static-files.rs`](examples/static-files.rs), which shows how to use the provided `handlers::static_files::*` handlers in order to serve static assets during development.\n\n## Dependencies \u0026 Features\n\naitch 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.\n\nTo function, aitch requires a small number of dependencies: `http`, `futures` and `bytes`.\n\nIn order to help you be productive quickly, aitch provides a number of optional features, which are currently enabled by default:\n\n - `server-hyper`: Provides a `Server`, which can run an `aitch::Handler` using the `hyper` web server. [(example)](examples/hello-world-sync.rs)\n - `server-tiny-http`: Provides a `Server`, which can run an `aitch::Handler` using the `tiny_http` web server. [(example)](examples/tiny_http.rs)\n - `json`: Provides a `Json\u003cT\u003e` type, which can wrap any type `T: serde::Deserialize + serde::Serialize`, allowing it to be used in requests and responses: `http::Request\u003cJson\u003cT\u003e\u003e`/`http::Response\u003cJson\u003cT\u003e\u003e`.  [(example)](examples/json.rs)\n - `mime_guess`: Uses the `mime_guess` crate to guess the MIME type of responses returned by the included `handlers::static_files::*` handlers.\n\nThese features will probably be split out into separate crates in the near future.\n\n## Is it fast?\n\nIt's pretty fast!\n\nWhen 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:\n\n```\n$ wrk --latency -t12 -c100 -d10s http://localhost:3000/\nRunning 10s test @ http://localhost:3000/\n  12 threads and 100 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency   837.87us    1.15ms  35.88ms   94.35%\n    Req/Sec    11.09k     1.55k   17.44k    75.25%\n  Latency Distribution\n     50%  630.00us\n     75%    1.06ms\n     90%    1.61ms\n     99%    3.45ms\n  1325352 requests in 10.02s, 135.24MB read\nRequests/sec: 132296.91\nTransfer/sec:     13.50MB\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjkillough%2Faitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjkillough%2Faitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjkillough%2Faitch/lists"}