Here's an example of how to create an HTTP server in Rust using the hyper library and read the request body as bytes and return a binary response:
main.rs1026 chars36 linesIn this example, we define a closure new_service that takes a Request and returns a Response. Inside this closure, we first extract the request body as bytes using the concat2 method. We then create a new Response object containing our binary response, with the content type set to application/octet-stream.
We use the hyper library's Server::bind method to start the server, passing in our closure as the service that will handle incoming requests.
Note that for more complex applications, you may want to use a different approach for handling the request body, such as streaming the bytes as they come in using a tokio::codec.
gistlibby LogSnag