Setting up our server
We need to set up a server in order to listen to requests, process them, and route them to specific views based on their URLs. This server will be the entry point to our application. In order to build our server, we must follow these steps:
- First, we will build our own cargo project and define our dependency on the Rocket frame with the following dependency, which can be found in the
Cargo.toml
file:[dependencies] tokio = { version = "0.2", features = ["full"] } warp = "0.2"
- Now, we can build our basic server with just one view in out
src/main.rs
file. First of all, we will import what we need with the following code:use warp::Filter;
This is all we need to import.
With this simple import statement, Warp provides us with a lot of tools. To demonstrate this, we are going to define some routes, pass in parameters, return some JSON, and launch a server. Essentially,
Filter
can extract some data from requests. This data can...