Skip to content
This repository was archived by the owner on Oct 29, 2021. It is now read-only.

Enhance params parsing #36

Closed
plwai opened this issue Jan 6, 2020 · 1 comment
Closed

Enhance params parsing #36

plwai opened this issue Jan 6, 2020 · 1 comment
Assignees
Labels
enhancement Enchancement for current feature invalid This doesn't seem right
Milestone

Comments

@plwai
Copy link
Member

plwai commented Jan 6, 2020

Enable Option as the type.

Proposal

Params

app.get("/paramtest/:id", |ctx: Context| async move {
    let param_test: Option<i32> = ctx.param("id")?;

    Ok(response::json(param_test, StatusCode::OK))
});

If :id cannot be parsed, it will be None.

Forms/Query

app.post("/formtest", |mut ctx: Context| async move{
    let param_test: Option<i32>= ctx.form().await?;

    Ok(response::json(param_test, StatusCode::OK))
});

If item cannot be found, it will be None. Apply to fields in struct as well.

@plwai plwai added the enhancement Enchancement for current feature label Jan 6, 2020
@plwai plwai added this to the V0.2 milestone Jan 6, 2020
@plwai plwai self-assigned this Jan 6, 2020
@jk-gan jk-gan mentioned this issue Jan 6, 2020
10 tasks
@plwai
Copy link
Member Author

plwai commented Jan 8, 2020

Close this issue since this is not applicable.

Reason

For the first case, the handler will not be hit if :id is not found.
For the second case, forms, json and string query come with keyvalue pair. If there is no struct, it is not possible to map the value.

@plwai plwai closed this as completed Jan 8, 2020
@plwai plwai added the invalid This doesn't seem right label Jan 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Enchancement for current feature invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant