Crate feather

Source
Expand description

§🪶 Feather: Middleware-First, DX-First Web Framework for Rust

Feather is a lightweight, middleware-first web framework for Rust, inspired by the simplicity of Express.js but designed for Rust’s performance and safety.

§Philosophy

  • Middleware-First: Everything in Feather is a middleware, or produces a middleware. This enables powerful composition and a familiar, flexible mental model.
  • DX-First: Feather is designed to be easy to use, with minimal boilerplate, clear APIs, and a focus on developer experience.

§Features

  • Express.js-like Routing: Use app.get style routing for simplicity and familiarity.
  • State Management: Manage application state efficiently using the Context API.
  • Error Handling: Runtime error handling for easier debugging and recovery.
  • Middleware Support: Create and chain middlewares for modular and reusable code.
  • All-in-One: Includes routing, middleware, logging, JWT authentication, and more.
  • Multithreaded by Default: Powered by Feather-Runtime for high performance without async.

§Getting Started

Add Feather to your Cargo.toml:

[dependencies]
feather = "~0.4"

§Quick Example

use feather::{App, AppContext, Request, Response, next, middleware};
fn main() {
    let mut app = App::new();
    app.get("/", middleware!(|_req, res, _ctx| {
        res.send_text("Hello, Feather!");
        next!()
    }));
    app.listen("127.0.0.1:5050");
}

§Middleware in Feather

Middleware is the heart of Feather. You can write middleware as a closure, a struct, or chain them together. The middleware! macro helps reduce boilerplate for closures:

app.get("/", middleware!(|req, res, ctx| {
    // ...
    next!()
}));

§State Management

Feather’s Context API allows you to manage application-wide state without extractors or macros. See the README for more details.

§Macros

  • next!: Syntactic sugar for Ok(MiddlewareResult::Next), reducing boilerplate in middleware implementations.
  • middleware!: Concise closure middleware definition.

Re-exports§

pub use crate::middlewares::MiddlewareResult;
pub use internals::App;
pub use internals::AppContext;

Modules§

internals
middlewares

Macros§

chain
A macro to chain multiple middlewares together.
This macro takes a list of middlewares and chains them together.
debug
Logs a message at the debug level.
error
Logs a message at the error level.
info
Logs a message at the info level.
json
Construct a serde_json::Value from a JSON literal.
middleware
The middleware! macro allows you to define middleware functions concisely without repeating type signatures.
next
This macro is just a syntactic sugar over the Ok(MiddlewareResult::Next) syntax just to clear some Boilerplate
trace
Logs a message at the trace level.
warn
Logs a message at the warn level.

Structs§

Request
Contains a incoming Http Request
Response

Enums§

Value
Represents any valid JSON value.

Type Aliases§

Outcome
This is just a type alias for Result<MiddlewareResult, Box<dyn Error>>;
Outcome is used in All middlewares as a return type.