How to read Request Body in Tokio-Hyper


Hi, I’m trying to build some http server using hyper.

I’m trying to get body of http request as Vec<u8>, but so far I haven’t been able to get it to work.

I’ve checked out example server implementation, but this basically just passes request body to response body.

So far I’ve tried below, but this gets blocked at "before fold".

fn call(&self, req: Request) -> Self::Future {
    let (method, uri, _version, headers, body) = req.deconstruct();
    match (&method, uri.path()) {
        (&Post, "/echo") => {
            let res = Response::new();
            let input: Vec<u8> = if let Some(len) = headers.get::<ContentLength>() {
                Vec::with_capacity(**len as usize)
            } else {
            debug!("before fold");
            future::result(body.fold(input, |mut acc, chunk| {
                Ok::<_, hyper::Error>(acc)
            }).and_then(move |body_vec| {
                debug!("body_vec ready: {}", body_vec.len());
        _ => future::ok(Response::new().with_status(StatusCode::NotFound)),

I’m still new to Futures and I’m trying to adapt to hyper’s shift to Tokio based API.
It would be great if someone can point me to the right direction.


Reading json body in Hyper

I got this working, by using CpuPool as getting started guide does.

Here’s complete example:


I got this working without use of CpuPool now:


Thank you very much. Not many people come back to their posts to update the results. I was able to fix a problem where I was stuck for a day thanks to your two replies (I used both). Keep it up, and happy new year.