Skip to content

bearcove/tower-cookies

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A tower (axum) cookies manager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%