Let's start implementing a microservice to store and serve images with an uploading files feature. To get incoming files, we have to read an incoming Stream of a Request. The Stream might be huge, so we shouldn't hold the whole file in memory. We will read the incoming data in chunks and write them immediately to a file. Let's create the main function of our microservice:
fn main() { let files = Path::new("./files"); fs::create_dir(files).ok(); let addr = ([127, 0, 0, 1], 8080).into(); let builder = Server::bind(&addr); let server = builder.serve(move || { service_fn(move |req| microservice_handler(req, &files)) }); let server = server.map_err(drop); hyper::rt::run(server);}
This looks like the other examples that we've created ...