The Router microservice uses the /signup route to resend a signup request to a users microservice bound to the 127.0.0.1:8001 address. This request creates a new users with filled from UserForm, passed with a parameter wrapped with the Form type. Look at the following code:
fn signup(params: Form<UserForm>) -> FutureResponse<HttpResponse> {
let fut = post_request("http://127.0.0.1:8001/signup", params.into_inner())
.map(|_: ()| {
HttpResponse::Found()
.header(header::LOCATION, "/login.html")
.finish()
});
Box::new(fut)
}
We call the post_request function that we declared before to send a POST request to a users microservice and if it returns a successful response, we return a response with a 302 status code. We create HttpResponseBuilder with the corresponding status code by the HttpResponse::Found function call. After this, we also set the LOCATION header to redirect the user to a login form with the header method call of HttpResponseBuilder. Lastly, we call finish() to create a HttpResponse from a builder and return it as a boxed Future object.
The function has a FutureResponse return type that is implemented as follows:
type FutureResponse<I, E = Error> = Box<dyn Future<Item = I, Error = E>>;
As you can see, it's a Box with a type that implements a Future trait.
Also, the function expects Form<UserForm> as a parameter. The UserForm structs are declared as follows:
#[derive(Deserialize, Serialize)]
pub struct UserForm {
email: String,
password: String,
}
As you can see, it expects two parameters: email and password. Both will be extracted from the query string of a request in the format of [email protected]&password=<secret>. The Form wrapper helps to extract data from the response's body.