| Crates.io | sbmstd |
| lib.rs | sbmstd |
| version | 0.6.4 |
| created_at | 2025-04-11 08:09:31.368447+00 |
| updated_at | 2025-07-24 02:57:20.688625+00 |
| description | Standard Middleware Library for Starberry |
| homepage | |
| repository | https://github.com/Redstone-D/starberry |
| max_upload_size | |
| id | 1629461 |
| size | 73,858 |
https://crates.io/crates/starberry
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")
}
(Learn how to use this by looking at the following repo as example)
https://github.com/Field-of-Dreams-Studio/sfx
By using Session middleware, you will be able to store session in the memory
session_ttl: u64, set the time for session to expire
SessionRW, access the Session content from this
pub static APP: SApp = Lazy::new(|| {
App::new().append_middleware::<Session>().build()
});
#[url(reg!(APP, LitUrl("session")))]