Summary
In this chapter, we learned about two Rocket components, State
and Fairing
. We can manage state objects and attach fairings upon building rockets, use the state
objects in route handling functions, and use the fairing
functions to execute callbacks on the build, after launch, on request, and on response.
We also created counter states and used them in the route handling functions. We also learned how to use sqlx
, made a database migration, made a database connection pool state, and used state
to query the database.
Afterward, we learned more about the Rocket initialization process and the building, igniting, and launching phases.
Finally, we changed the counter state into a fairing and created a new fairing to inject a custom HTTP header into the incoming requests and outgoing responses.
Armed with that knowledge, you can create reusable objects between route handling functions, and create a method that can be executed globally between requests and responses.
...