Reading a body from a stream

In fact, the body of a request in a hyper crate is a stream. You can't get access to the full body immediately, but you can read incoming chunks, write them to a vector, and use the resulting data set as a single object.

We don't have access to the whole body because it may be a huge block of data that we can't keep in the memory. Our service could be used, for example, to upload multiple terabytes of data files or for video streaming.

Since we're using an asynchronous approach, we can't block the current thread while we read the stream to the end. This is because it would block the thread and cause the program to stop working, because the same thread is used for polling streams.

The serde crate doesn't support ...

Get Hands-On Microservices with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.