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

POST Example #2

Closed
codecandy2015 opened this issue Dec 16, 2020 · 4 comments
Closed

POST Example #2

codecandy2015 opened this issue Dec 16, 2020 · 4 comments

Comments

@codecandy2015
Copy link

Hi,
I am trying to do a simple POST. I tried this,
match (req.method(), req.path()) { ("GET", "/json") => { rsp.header("Content-Type: application/json"); serde_json::to_writer( BodyWriter(rsp.body_mut()), &HelloMessage { message: "Hello, World!", }, )?; }, ("POST", "/json") => { rsp.header("Content-Type: application/json"); serde_json::to_writer( BodyWriter(rsp.body_mut()), req.data(), )?; }, ("GET", "/plaintext") => { rsp.header("Content-Type: text/plain").body("Hello, World!"); }, _ => { rsp.status_code("404", "Not Found"); }, }

However, I am not able to access the request Body. Do you have any suggestions perhaps ?
Kind regards
Savi

@janderadutra
Copy link

pub fn body(&self) -> &[u8] {
unimplemented!()
}
I wanted to use this api

@evmer
Copy link

evmer commented Sep 3, 2022

I submitted a pull request to add the implementation of the body() api #3

@janderadutra
Copy link

Thanks!!

StratusFearMe21 added a commit to StratusFearMe21/may_minihttp that referenced this issue Nov 22, 2022
Xudong-Huang added a commit that referenced this issue Feb 18, 2024
Xudong-Huang added a commit that referenced this issue Feb 18, 2024
Xudong-Huang added a commit that referenced this issue Feb 18, 2024
Xudong-Huang added a commit that referenced this issue Feb 19, 2024
@Xudong-Huang
Copy link
Owner

I think we can close this now. the request has a body() API which impl io::Read/io::BufRead to read out the body

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

No branches or pull requests

4 participants