7 releases

Uses new Rust 2024

0.6.4 Jul 24, 2025
0.6.3 Jul 9, 2025
0.6.2 Jun 19, 2025
0.6.0 May 31, 2025
0.4.0 Apr 11, 2025

#1390 in HTTP server

28 downloads per month
Used in 2 crates

MIT and GPL-3.0-or-later

430KB
6.5K SLoC

Please refer to the following link

https://crates.io/crates/starberry

The standard starberry middleware library

Cors

Safty setting for APP & Cors support

We are now able to add config to both APP and urls. For APP, we are able to set the config/static by using methods

pub static APP: SApp = Lazy::new(|| {
    App::new()
        .single_protocol(ProtocolBuilder::<HttpReqCtx>::new() 
            .append_middleware::<CookieSession>() // Append the cors middleware. The cors middleware's setting is a AppCorsSettings data  
        ) 
        .set_config( // Add a config data, which is a TypeID, Any HashMap 
            prelude::cors_settings::AppCorsSettings::new() // Store a data with the type of AppCorsSettings into config. The middleware will be able to figure this stored data out by using its TypeID 
        ) 
        .set_local( // Set a static data, which is a String, Any HashMap. When getting data you need to specify both String and Type 
            "key": "MySuperSecuredAdminKeyWhichIsSoLongThatCanProtectTheServerFromAnyAttack" 
        )
        .build() 
}); 

While for the Url, we are able to store params by using the #[url] macro

#[url(APP.reg_from(&[TEST_URL.clone(), LitUrl("get")]), config=[HttpSafety::new().with_allowed_method(HttpMethod::GET)])]  
async fn get_only() -> HttpResponse { 
    text_response("Get only")  
} 

#[url(APP.reg_from(&[TEST_URL.clone(), LitUrl("post")]), config=[HttpSafety::new().with_allowed_methods(vec![HttpMethod::POST])])]  
async fn post_only() -> HttpResponse { 
    text_response("Post only")  
}

Session (Based On Cookie)

(Learn how to use this by looking at the following repo as example)

https://github.com/Field-of-Dreams-Studio/sfx

Session (Based on Cache, Deadlock is possible do not use this)

Function

By using Session middleware, you will be able to store session in the memory

APP Statics & Configs

session_ttl: u64, set the time for session to expire

Request Context

SessionRW, access the Session content from this

Example

pub static APP: SApp = Lazy::new(|| {
    App::new().append_middleware::<Session>().build()
}); 

#[url(reg!(APP, LitUrl("session")))] 

Dependencies

~26–39MB
~808K SLoC