January 2019
Intermediate to advanced
520 pages
14h 32m
English
We want to cover all basic CRUD operations. Using the principles of REST, there are suitable HTTP methods that fit these operations—POST, GET, PUT, and DELETE. We can use the match expression to detect the corresponding HTTP method:
match (method, user_id) { // Put other branches here _ => { response_with_code(StatusCode::METHOD_NOT_ALLOWED) },}
Here, we used a tuple with two values—a method and a user identifier, which is represented by the Option<UserId> type. There is a default branch that returns the METHOD_NOT_ALLOWED message (the 405 HTTP status code) if a client requests an unsupported method.
Let's discuss every branch of match expression for every operation.
Read now
Unlock full access