-
Notifications
You must be signed in to change notification settings - Fork 147
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
gloo net add .json
convenience method for Request
#199
Comments
Request
.json
convenience method for Request
you also have to add an |
Would you like to PR an implementation? |
If something like the following would suffice (not sure given that the surrounding methods return /// convenience method for json request bodies
pub fn json<T: Serialize + ?Sized>(self, value: &T) -> Result<Self,Error> {
let json = serde_json::to_string(value)?;
Result::Ok(
self.header("Content-Type", "application/json")
.body(json)
)
} It's been a bit since I've done any Rust--apologies if that is bad 😬 |
This can probably be closed, as the requested change was added in #204 |
Summary
add
.json
convenience method forRequest
Motivation
makes sending json parameters more ergonomic
Detailed Explanation
right now, we must do a
.body(serde_json::to_string(&JsonSerializableStruct { ... }).unwrap())
, which isn't as ergonomic for an http library as, for example,reqwest
with which you can do.json(&JsonSerializableStruct { ... })
Drawbacks, Rationale, and Alternatives
i don't think there are drawbacks, refer to
reqwest source
for implementationUnresolved Questions
The text was updated successfully, but these errors were encountered: