Implement and run an HTTP service with may_minihttp
masterTo create an HTTP server, you must implement the HttpService trait for your service struct. The call method receives a Request and a mutable reference to a Response, where you can set the response body. You then wrap your service in an HttpServer and call .start(address) to begin listening on the specified network address.
extern crate may_minihttp;
use std::io;
use may_minihttp::{HttpServer, HttpService, Request, Response};
#[derive(Clone)]
struct HelloWorld;
impl HttpService for HelloWorld {
fn call(&mut self, _req: Request, res: &mut Response) -> io::Result<()> {
res.body("Hello, world!");
Ok(())
}
}
// Start the server in `main`.
fn main() {
let server = HttpServer(HelloWorld).start("0.0.0.0:8080").unwrap();
server.join().unwrap();
}