Thruster icon indicating copy to clipboard operation
Thruster copied to clipboard

[FEATURE REQUEST] Make extended example on generate Context

Open Israel-Laguan opened this issue 1 year ago • 2 comments

Current context examples are limited, and certain standard procedures in servers related to use context (setting certain request states like user auth or moving a value from one middleware to another) are not clear on how to do in thruster.

As a user, I would like to add a new field to the context, for example

  • there is an endpoint to access certain DB records, that I need to be "private"
  • in middleware, I would like to authenticate the user and know her/his role and what permissions she/he has
  • I would like to save the role in the context as a Map or HashMap (to get later like context.user.get("roles"))
  • Then in another middleware read this context field and use it in certain logic.

Another use case would be to validate input in one middleware, parse/map it, then use this modified data in another middleware.

Request

  • Add an example of creating a custom Context with custom optional fields
  • Add an example of setting a custom field in one middleware, and reading it in other middleware (or controller)

Israel-Laguan avatar Oct 05 '22 08:10 Israel-Laguan

Please see #232 for examples (specifically the custom Auth one)!

trezm avatar Oct 11 '22 13:10 trezm

Solved in https://github.com/thruster-rs/Thruster/pull/232

Israel-Laguan avatar Oct 13 '22 08:10 Israel-Laguan

Can this be closed?

Israel-Laguan avatar Oct 25 '22 20:10 Israel-Laguan