Generic route for current user in .NET Core

I am creating an API in .NET Core 1.1. I have many routes, for example /api/users/:id/posts, to receive user messages with the specified ID. Other sites that I found (especially Discord ) accept a generic parameter, such as @meto link to the current user instead of indicating I would. How can I implement this in .NET Core?

I take the JWT in the header Authorization, and I have a custom object Userthat is populated with its information using special middleware, including the user ID. Therefore, I must have an identifier at the time of using any route or controller, but I do not know how I can specify a common route that this identifier will automatically use when called using @meor something like that. How can i do this?

EDIT: When I get some time, I'm going to write middleware to implement it. I leave the question open so that I can publish the solution when I can write it.

+4
source share

Source: https://habr.com/ru/post/1663271/


All Articles