A web application framework supplies the HTTP implementation, server, runtime, and conventions for routing requests to handlers. It guides how requests are accepted and answered, while application business logic remains yours to build. section 2.2 section 3.2.1
Before building an API, start with a minimal working app and learn how the framework expects routes and handlers to be written. Check which request-handling features it provides and how difficult any missing features would be to add. section 3.2.1
Use these checkpoints to assess a framework:
- How does it parse paths, HTTP methods, request bodies, and URI parameters? section 3.2.1
- How does it support middleware, shared objects such as database connections, responses, sessions, and cookies? section 3.2.1
- Consider whether it is actively maintained and has community support. section 2.3
Listing 2.21 A minimal Rust HTTP server with Warp
use warp::Filter;
#[tokio::main]
async fn main() {
let hello = warp::get()
.map(|| format!("Hello, World!"));
warp::serve(hello)
.run(([127, 0, 0, 1], 1337))
.await;
}
A minimal Warp server defines a GET route, serves it on localhost, and awaits the server using Tokio. section 2.2
