Skip to content

std::format for application/x-www-form-urlencoded #1478

@octaltree

Description

@octaltree

Describe the feature you'd like
I want yew::format::urlencoded::UrlEncoded(T) format request to application/x-www-form-urlencoded and parse response.

Is your feature request related to a problem? Please describe. (Optional)
I don't know why this feature is not implemented.

Describe alternatives you've considered (Optional)
For my app, I implemented this with serde_urlencoded.

pub struct UrlEncoded<T>(T);

impl<'a, T> Into<Result<String, anyhow::Error>> for UrlEncoded<&'a T>
where
    T: serde::Serialize
{
    fn into(self) -> Result<String, anyhow::Error> { Ok(serde_urlencoded::to_string(self.0)?) }
}

#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct Request {
    ident: String,
    password: String
}

#[test]
fn encode_request() {
    let req = Request {
        ident: "foo@example.com".into(),
        password: "0000".into()
    };
    let rb: Result<String, anyhow::Error> = UrlEncoded(&req).into();
    let b = rb.expect("failure serialize");
    assert_eq!("ident=foo%40example.com&password=0000", b);
}

Additional context (Optional)

Questionnaire

  • I'm interested in implementing this myself but don't know where to start
  • I would like to add this feature
  • I don't have time to add this right now, but maybe later

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions