|
magpie
|
The context object is a global passed to every route. Functionally, it acts as userdata in many C APIs.
A default implementation, magpie::data::CommonData exists, though creating your own object even if you don't use data is strongly recommended. This makes it easier to add to the object after the fact, especially if you prefer to avoid, or otherwise cannot use auto in your function signatures:
You can put anything you want in this struct, but note that it's shared across all threads, including concurrently, and provides no facilities for thread safety. If you need thread safety, you must implement it yourself, or otherwise make sure the things you put in it are safe.
This context object can be used to keep track of session stores, database threadpools, or whatever other global state you have. It's provided to all endpoints and middlewares.