#axum #cookie #cookies #tower

tower-cookies

Cookie manager middleware for tower

13 releases (7 breaking)

0.8.0 Nov 25, 2022
0.7.0 Jun 9, 2022
0.6.0 Apr 1, 2022
0.5.1 Feb 23, 2022
0.3.0 Nov 18, 2021

#172 in Web programming

Download history 605/week @ 2022-10-14 762/week @ 2022-10-21 1056/week @ 2022-10-28 949/week @ 2022-11-04 1147/week @ 2022-11-11 1007/week @ 2022-11-18 852/week @ 2022-11-25 969/week @ 2022-12-02 1104/week @ 2022-12-09 762/week @ 2022-12-16 603/week @ 2022-12-23 860/week @ 2022-12-30 1022/week @ 2023-01-06 892/week @ 2023-01-13 822/week @ 2023-01-20 866/week @ 2023-01-27

3,782 downloads per month
Used in 6 crates (4 directly)

MIT license

24KB
476 lines

License Crates.io Documentation

tower-cookies

A cookie manager middleware built on top of tower.

Example

With axum:

use axum::{routing::get, Router};
use std::net::SocketAddr;
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(handler))
        .layer(CookieManagerLayer::new());

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

async fn handler(cookies: Cookies) -> &'static str {
    cookies.add(Cookie::new("hello_world", "hello_world"));

    "Check your cookies."
}

A complete CRUD cookie example in examples/counter.rs

Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

Contributing

We appreciate all kinds of contributions, thank you!

Note on README

The README.md file isn't meant to be changed directly. It instead generated from the crate's docs by the cargo-readme command:

  • Install the command if you don't have it: cargo install cargo-readme
  • Change the crate-level docs in src/lib.rs, or wrapping text in README.tpl
  • Apply the changes: cargo readme > README.md

If you have rusty-hook installed the changes will apply automatically on commit.

License

This project is licensed under the MIT license.

Dependencies

~2.4–8MB
~132K SLoC