Is crate/formdata sample code broken? how to handle form posts?

  1. I am writing a POST handler in Rust via hyper.

  2. Post for a single file works (so basic setup fine with hyper).

  3. Now, I want to handle form posts.

I am looking at formdata - Rust

it has sample code:

fn handler(hyper_request: Request, res: Response) {
  let (_, _, headers, _, _, mut reader) = hyper_request.deconstruct();
  1. Here is my problem: Request in hyper - Rust does not have a deconstruct .

  2. What is the easiest way to handle form POST requests in Rust/hyper ?

Nothing is broken. Just look at the dependencies. formdata requires hyper 0.10.x, but you linked to the latest version which is 0.14.0. The actual dependent, 0.10, does have a deconstruct() method.


Thanks, I see. I'd prefer to not downgrade hyper version. Any recommendations on how to handle this ?

You'd either parse the form data yourself, or search for a crate that supports hyper 0.14. A quick Google search brings up multipart, which seems to depend on Hyper 0.10 too, although it provides an apparently generic parser, so you might be able to get away with it.

@H2CO3 : Thanks.


Does anyone else find multipart/ at master · abonander/multipart · GitHub absolutely counter intuitive ?

  1. we are defining two new structs

  2. we change the TOP LEVEL handler

in contrast I was expecting something that can be done via local modification of the POST handler

It's to not use the hyper directly. The hyper is a low level HTTP library you can build HTTP clients and server frameworks with it. It's not a convenient HTTP server framework on itself. Various HTTP frameworks including axum, warp, salvo, poem are already built on it. For example, it's pretty easy to handle multipart form upload with axum.