thruster-rs / Thruster

A fast, middleware based, web framework written in Rust
MIT License
1.07k stars 47 forks source link

too basic context #70

Closed AlbanMinassian closed 6 years ago

AlbanMinassian commented 6 years ago

As a new user, I find it constraining to code (each time) my own "context.rs" to start a new project. it's not intuitive.

Some basic methods in BasicContext should be proposed by default which allow to define headers (add, del) and define the return code (404)

Thanks Ami44

trezm commented 6 years ago

I agree. I think, in general, BasicContext should provide a relatively generic but capable experience for those getting started. As such, I believe the methods should be:

fn set_header(key: &str, val: &str);
fn remove_header(key: &str);
fn set_status_code(code: u32, message: &str);
AlbanMinassian commented 6 years ago

why not

koa or express methods

beware

res.status(code) koa or express - is not necessary to pass second string params

ami44

trezm commented 6 years ago

I have a few questions;

On Mon, Sep 10, 2018 at 9:28 AM Ami44 notifications@github.com wrote:

why not

koa or express methods

beware

res.status(code) koa https://github.com/koajs/koa/blob/master/docs/api/response.md#responsestatus or express http://expressjs.com/fr/api.html#res.status - is not necessary to pass second string params

ami44

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/trezm/Thruster/issues/70#issuecomment-419911613, or mute the thread https://github.com/notifications/unsubscribe-auth/ABNnLRQmoqQR6WITVWjK6GhJI9oyfU8lks5uZmjkgaJpZM4WhVN_ .

AlbanMinassian commented 6 years ago

Q1: Is there a reason to exactly align with koa and express on names? R1: for reasons of consistency "Based on frameworks like Koa, and Express" at front page https://github.com/trezm/Thruster#intuitive and for marketing reasons: to attract more koa or express developers to thruster because they will quickly find the same methods (et get more stars than actix-web :-))

Q2: What is the functional difference for the developer between set and append? R2: I think "set" should overwrite the previous value if key exists, otherwise call append

Q3: do you think that's easier than passing a blank string R3: no idea! see my response R1

Ami44

trezm commented 6 years ago

Hmm, valid points all around. I guess since this isn't like it lives in the trait, it would be worth going through the koa and/or express libraries and just copying over a bunch of methods to the BasicContext.

For set vs. append, I think we'll only support set for simplicity's sake. My guess is that append will actually create a comma separated list of values in Koa or Express, but we can leave that for a later exercise :). I'll mark this as an improvement for dev!

To reiterate, we'll include:

fn set(key: &str, val: &str);
fn remove(key: &str);
fn status(code: u32);