Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use serde to more easily get query parameters #416

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

BrandonDyer64
Copy link
Contributor

Allows the user to do something like this:

#[derive(Deserialize)]
struct MyQueryParams {
    a: i32,
    b: bool,
    c: String,
}

router.get("/route", |req, _ctx| {
    let query: MyQueryParams = req.query()?;

    // ?a=2&b=true&c=Hello
    assert_eq!(
        query,
        MyQueryParams {
            a: 2,
            b: true,
            c: "Hello".into(),
        }
    );
})

This is the inverse implementation of what reqwest does for building queries using serde.

@kflansburg kflansburg self-requested a review November 28, 2023 18:05
@kflansburg kflansburg merged commit c57f7a6 into cloudflare:main Nov 29, 2023
3 checks passed
@BrandonDyer64 BrandonDyer64 deleted the request-query branch December 3, 2023 05:10
jdon pushed a commit to jdon/workers-rs that referenced this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants