Skip to content

adding .json() method for better ergonomics similar to reqwest crate #63

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

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

calvinrp
Copy link
Contributor

Improves ergonomics for working with JSON request and responses:

  • response.body_mut().json::<T>().await?;
  • Request::post("https://postman-echo.com/post").json(&data)?;

Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good, just one question

@@ -26,8 +31,6 @@ impl BodyKind {
.parse::<u64>()
.map_err(|_| InvalidContentLength)?;
Ok(BodyKind::Fixed(content_length))
} else if headers.contains_key(TRANSFER_ENCODING) {
Ok(BodyKind::Chunked)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this deletion is for - was there a bug here?

Copy link
Contributor Author

@calvinrp calvinrp Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy spotted this. The else block below it returned the same thing, Ok(BodyKind::Chunked)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't even consider that, I was focused on the transfer encoding aspect.

@pchickey pchickey merged commit 5f3a273 into bytecodealliance:main Feb 18, 2025
4 checks passed
@calvinrp calvinrp deleted the opt-feat-serde-json branch February 18, 2025 16:37
@pchickey pchickey mentioned this pull request Feb 18, 2025
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