Handling HTTP requests using Hyper
When it comes to building our HTTP server, we will implement all the server logic in the src/main.rs
file. First, we import what we need with the following code:
use tokio::sync::{mpsc, mpsc::Sender}; use hyper::{Body, Request, Response, Server}; use hyper::body; use hyper::service::{make_service_fn, service_fn}; use serde_json; use serde::Deserialize; use std::net::SocketAddr;
At this stage in the book, these imports should not be confusing to you. Even though we have imported from the hyper
module, the imports are self-explanatory. We will extract data from a request, create a service to process our request, and create an HTTP server to listen to incoming requests.
We will also need to utilize the actors that we have created. Our actors can be imported using the following code:
mod actors; use actors::state::StateActor; use actors::runner::RunnerActor; use actors::messages::StateActorMessage; use actors::messages::MessageType;
With...