# πͺΆ Feather
**Feather** is a lightweight, DX-first web framework for Rust β inspired by the simplicity of Express.js, but designed for Rustβs performance and safety.
> π§ No async.
> π§± Middleware-first.
> β‘ Just works.
---
## β¨ Why Feather?
- π§± **Middleware-First Architecture**
Everything is a middleware β route handlers, auth, logging, error handling β all composable and clean.
- πͺΆ **Lightweight and Fast**
Feather uses traditional threads instead of async, avoiding the overhead and complexity of Rustβs async model.
- π¦ **Easy State Management Using Context**
In the recent version Feather implemented the Context API that allows it have easy state managment without the use of Extractors/Macros
- π§βπ» **Developer Experience First**
Featherβs API is minimal, ergonomic, and readable β no lifetimes, no `.await`,
- π¦ **Modular and Extensible**
Build the framework you want with plug-and-play middleware, simple traits, and clear primitives.
- π¨ **Great Tooling Out Of the Box**
With the use of the [Feather-CLI](https://github.com/BersisSe/feather-cli/tree/main) Creating API's and Web Servers Become a Breeze.
---
## π Getting Started
Add Feather to your `Cargo.toml`:
```toml
[dependencies]
feather = "0.3.1"
```
---
## π§ Quick Example
```rust,no_run
use feather::{App, AppContext, MiddlewareResult,Request, Response};
fn main() {
let mut app = App::new();
app.get("/",|_req: &mut Request, res: &mut Response, _ctx: &mut AppContext| {
res.send_text("Hello, world!");
MiddlewareResult::Next
});
app.listen("127.0.0.1:3000");
}
```
βοΈ Thatβs all β no async, no magic.
---
## π Middleware in Feather
Middleware is the heart of Feather. Write it as a closure, a struct, or chain them together:
```rust,no_run
use feather::{App, AppContext, Request, Response};
use feather::middleware::builtins;
use feather::middleware::{Middleware, MiddlewareResult};
// Implementors of the Middleware trait are middleware that can be used in a Feather app.
struct Custom;
impl Middleware for Custom {
fn handle(&self,request: &mut Request,_response: &mut Response,_ctx: &mut AppContex) -> MiddlewareResult {
println!("Now running some custom middleware (struct Custom)!");
println!("And there's a request with path: {:?}", request.uri);
MiddlewareResult::Next
}
}
fn main() {
let mut app = App::new();
app.use_middleware(builtins::Logger);
app.use_middleware(Custom);
app.use_middleware(|_req: &mut Request, _res: &mut Response, _ctx: &mut AppContext| {
println!("Now running some custom middleware (closure)!");
MiddlewareResult::Next
});
app.get("/",|_req: &mut Request, res: &mut Response, _ctx: &mut AppContext| {
res.send_text("Hello, world!");
MiddlewareResult::Next
});
app.listen("127.0.0.1:3000");
}
```
---
## π¦ State Management using the Context API
Feather's new Context API allows you to manage application-wide state without extractors or macros. Here's an example:
```rust,no_run
use feather::{App, AppContext, MiddlewareResult, Response, Request};
struct Counter {
pub count: i32,
}
fn main() {
let mut app = App::new();
let counter = Counter { count: 0 };
app.context().set_state(counter);
app.get("/", move |_req: &mut Request, res: &mut Response, ctx: &mut AppContext| {
let counter: &mut Counter = ctx.get_mut_state::<Counter>().unwrap();
counter.count += 1;
res.send_text(format!("Counted! {}", counter.count));
MiddlewareResult::Next
});
app.get("/count", move |_req: &mut Request, res: &mut Response, ctx: &mut AppContext| {
let counter = ctx.get_state::<Counter>().unwrap();
res.send_text(counter.count.to_string());
MiddlewareResult::Next
});
app.listen("127.0.0.1:5050");
}
```
Context Is more useful when combined with Database/File Accesses
## π Built-in JWT Authentication
Feather has native JWT middleware activated using a cargo feature `jwt`:
```toml
[dependencies]
feather = { version = "0.3.1", features = ["jwt"] }
```
```rust,no_run
use feather::jwt::{generate_jwt, with_jwt_auth};
use feather::{App, AppContext};
fn main() {
let mut app = App::new();
app.get("/auth",with_jwt_auth("secretcode", |_req, res,_ctx, claim| {
println!("Claim: {:?}", claim);
res.send_text("Hello, JWT!");
feather::MiddlewareResult::Next
}),
);
// Check the JWT Example for more complete version!
app.listen("127.0.0.1:8080")
}
```
No need to reach out for 3rd Party Crates Feather Got you Covered!
---
## π§± Goals
- πͺΆ Be the simplest Rust web framework to get started with
- π§© Be modular and easy to extend
- π‘ Focus on DX without sacrificing Rust's safety and performance
---
## π€ Contributing
PRs welcome!
If youβve got ideas or bugs, [open an issue](https://github.com/your_repo_link/issues) or submit a pull request.
```bash
# Getting started with dev
git clone https://github.com/BersisSe/feather.git
cd feather
cargo run --example app
```
---
## π License
Feather is MIT licensed. See [LICENSE](./LICENSE).
---
## π Acknowledgments
Feather is inspired by [Express.js](https://expressjs.com) and exists to bring that same productivity to Rust.
Thanks to the Rust community for the incredible ecosystem this project builds on.
---
## π£ Spread the Word
If you like Feather:
- β Star it on [GitHub](https://github.com/BersisSe/feather)
- π° Share it on Reddit, HN, or Discord
- π Build something and show us!
---