Signup

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.

The actix_web crate limits requests and responses by size. If you want to send or receive huge payloads, you have to override defaults that often won't allow requests larger than 256 KB. For example, if you want to increase the limit, you can use the FormConfig struct provided with the with_config method call of Route, and call the limit method of a config with the desired quantity of bytes. The HTTP client is also limited by response size. For example, if you try to read a large JSON object from a JsonBody instance, you may need to limit it with the limit method call before you use it as a Future object.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.21.158