January 2019
Intermediate to advanced
520 pages
14h 32m
English
Our microservice contains two handlers. The first handles the request for the /list path and returns all comments from a database:
#[get("/list")]fn list(conn: Db) -> Json<Vec<Comment>> { Json(Comment::all(&conn))}
As you can see, a handler in the Rocket framework is a function that takes parameters that rocket automatically binds and expects a function to return a result. Our list function returns a list of comments in JSON format. We use the Comment model declared in the comment module to extract all comments using a connection from a pool provided as an argument of function.
To declare a method and a path, we add the get attribute to a function declaration with the path we need. The get attribute allows you to call a ...
Read now
Unlock full access