huio
HTTP framework for Rust built on top of Actix-Web.
Installation
[]
= "0.1.0"
= { = "1", = ["full"] }
Quick start
use ;
async
async
Routing
use Router;
let api = new
.get
.post
.nest;
let root = new.nest;
Path parameters use the :name syntax and are accessed via req.param("name"). Trailing slashes are normalized automatically. HEAD requests are handled automatically if a GET handler is registered.
Request
req.path // &str
req.method // HttpMethod
req.param // Option<&str> — path parameter
req.query // Option<&str> — query string parameter
req.query_all // &HashMap<String, String>
req.headers // HashMap<String, String>
req.body // Vec<u8>
Response
ok // 200 text/plain
json // 200 application/json (accepts any impl Serialize)
not_found // 404
method_not_allowed // 405
internal_error // 500
// Builder methods (chainable):
ok
.status.unwrap
.header
Middleware
Middleware is Arc<dyn Fn(Request, Next) -> BoxFuture<Response> + Send + Sync>.
Middlewares are applied per-router and inherited by nested routers.
use Arc;
use Middleware;
let logger: Middleware = new;
let router = new
.middleware
.get;
Server configuration
default
.hostname // default: "0.0.0.0"
.port // default: 80
.basepath // optional base prefix
.router
.build?
.run
.await?;
build() returns HuIOServer<Ready>, which exposes .hostname(), .port(), .basepath() getters and .run().
HTTP methods
GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS — registered via same-named builder methods on Router.
License
MIT