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
[]
= "1.0.0"
Quick-start
use *;
use Rejection;
async
Route builders
Plain route (no body / no query params)
get
.handle;
JSON body
Declare the expected body type with .json::<T>(). T must implement serde::DeserializeOwned.
use Deserialize;
post
.
.handle;
Query parameters
Declare the query-string type with .query::<T>(). T must implement serde::DeserializeOwned.
use Deserialize;
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! macro (prelude)
The unwarp! macro is a shorthand for the two helpers above:
// equivalent to Unwarp::with_status(Status::Created, warp::reply::json(&item))
unwarp!
// equivalent to Unwarp::json(&value)
unwarp!
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 *;
use Rejection;
async
Prelude
Import everything you need in one line:
use *;
// re-exports: Unwarp, unwarp!, RouteBuilder, Status
License
MIT — see LICENSE.