shio-rs icon indicating copy to clipboard operation
shio-rs copied to clipboard

Greatly simplify creation of Request and Context

Open mehcode opened this issue 8 years ago • 3 comments

Currently to create a Context its .. really hairy.

https://github.com/mehcode/shio-rs/blob/724880d5e5e644d63df096445b912a2fa36bcaf1/lib/src/router/mod.rs#L212-L215

We should be able to do something like:

let context: Context = ContextBuilder::new(handle)
    // Set method on request in context (default: Get)
    .method(Method::Get)
    // Set URI on request (default: /)
    .uri("/")
    // With shared storage (default: Empty)
    .shared(other_context.shared().clone())
    // Returns a Result<Context> if URI parsing failed or something
    .finalize()?;

mehcode avatar Sep 15 '17 05:09 mehcode

I've started working on it. Currently I make it into util mod, but maybe into context (or testing, because mostly here for testing) is better ?

Meralis40 avatar Sep 15 '17 09:09 Meralis40

It'd make the most sense in a context/builder.rs file I'd think. Going by the Rust API guidelines it should probably be named shio::context::Builder.

We should also have a Context::builder(handle) or Context::build(handle) (unsure what name there, the http crate uses builder) method that is equivalent to shio::context::Builder::new(handle).

mehcode avatar Sep 15 '17 09:09 mehcode

Ok, I will do that.

Meralis40 avatar Sep 15 '17 09:09 Meralis40