Implementing route handlers
Here, we will make an application that handles a route. We are reusing the first code that we wrote in this chapter. The idea is that we have several user data, and we want to send requests that will select and return the selected user data according to the ID sent in the request. In this part, we will implement the request and selecting part of the route handlers. In the next section, we will learn how to create a custom response type. In the subsequent section, we will create a handler for when the request does not match any user data we have. And finally, in the last section, we will create a default error handler to handle invalid requests.
Let's start by copying the first code into a new folder. After that, in src/main.rs
, add a User
struct after the Filter
definition:
struct Filters {
...
}
#[derive(Debug)]
struct User {
uuid: String,
name: String,...