unwarp
A minimal, ergonomic wrapper around warp — define routes, attach handlers, and serve. No boilerplate, no filter chains.
Overview
unwarp sits on top of warp and hides the filter-composition ceremony behind a simple builder API:
- Pick an HTTP method and path with
RouteBuilder. - Optionally specify a JSON body or query-string type.
- Attach an async handler with
.handle(...)— you get back a type-erased_Filter. - Register every route on an
Unwarpinstance with.route(...). - Call
.serve(addr).awaitto start listening.
Installation
[]
= "2.0.0"
[]
= { = "1", = ["macros", "rt-multi-thread"] }
unwarpre-exportswarpinternally. You do not need to addwarpto your ownCargo.toml.
Quick-start
use *; // also brings `warp` module into scope
async
Route builders
Plain route (no body / no query params)
use *;
get
.handle;
JSON body
Declare the expected body type with .json::<T>(). T must implement serde::DeserializeOwned.
use Deserialize;
use *;
post
.
.handle;
Query parameters
Declare the query-string type with .query::<T>(). T must implement serde::DeserializeOwned.
use Deserialize;
use *;
get
.
.handle;
Supported HTTP methods
| Builder constructor | HTTP method |
|---|---|
RouteBuilder::get(path) |
GET |
RouteBuilder::post(path) |
POST |
RouteBuilder::put(path) |
PUT |
RouteBuilder::delete(path) |
DELETE |
RouteBuilder::patch(path) |
PATCH |
RouteBuilder::head(path) |
HEAD |
RouteBuilder::options(path) |
OPTIONS |
Constructing responses
Unwarp ships two static helpers so you rarely need to write Ok::<_, Rejection>(...) yourself.
Unwarp::with_status
delete
.handle;
Unwarp::json
get
.handle;
Unwarp::json_with_status
Serialises a value as JSON and sets the status code in one call. Useful for 201 Created, 202 Accepted, etc.
use Serialize;
use *;
post
.
.handle;
unwarp! macro (prelude)
The unwarp! macro is a shorthand for the two helpers above:
// Serialise value as JSON and wrap with a status code
unwarp!
// Wrap any warp::Reply (html, plain text, etc.) with a status code
unwarp!
// Shorthand for Unwarp::json(&value)
unwarp!
Why
json =>? Bothunwarp!(status, json_val)andunwarp!(status, string_val)look identical to the macro engine — it matches on token structure, not types. Thejson =>keyword discriminator makes the two arms syntactically distinct so the right one is always chosen.
Status enum
A typed representation of common HTTP status codes, convertible to warp::http::StatusCode via Into.
| Variant | Code |
|---|---|
Status::Ok |
200 |
Status::Created |
201 |
Status::Accepted |
202 |
Status::NoContent |
204 |
Status::MovedPermanently |
301 |
Status::Found |
302 |
Status::NotModified |
304 |
Status::TemporaryRedirect |
307 |
Status::PermanentRedirect |
308 |
Status::BadRequest |
400 |
Status::Unauthorized |
401 |
Status::Forbidden |
403 |
Status::NotFound |
404 |
Status::MethodNotAllowed |
405 |
Status::Conflict |
409 |
Status::Gone |
410 |
Status::UnprocessableEntity |
422 |
Status::TooManyRequests |
429 |
Status::InternalServerError |
500 |
Status::NotImplemented |
501 |
Status::BadGateway |
502 |
Status::ServiceUnavailable |
503 |
Status::GatewayTimeout |
504 |
Full example
use ;
use *; // brings Unwarp, RouteBuilder, Status, unwarp!, and warp into scope
async
Prelude
Import everything you need in one line:
use *;
// re-exports: Unwarp, unwarp!, RouteBuilder, Status
// also re-exports: warp (so warp::reply::*, warp::Rejection, etc. work without a warp dep)
License
MIT — see LICENSE.