Я пишу приложение Express JS, и мне нужно рассчитать маршрут с учетом функции контроллера или пути маршрута.
Например:
let myUrl = functionToGetRoutePath(ThingsController.getThing); // would return https://host/api/v1/things/{id}
// Or
let myUrl = functionToGetRoutePath('/things/{id}'); // would return https://host/api/v1/things/{id}
Или, учитывая параметры, он может заполнить параметры URL, например:
let myUrl = functionToGetRoutePath(ThingsController.getThing, { id: 1 }); // would return https://host/api/v1/things/1
// Or
let myUrl = functionToGetRoutePath('/things/{id}', { id: 1 }); // would return https://host/api/v1/things/1
Исходя из .NET, это довольно легко с помощью UrlHelper:
new UrlHelper(Request).Link("Things Route Name", new { id = 1 }); // returns https://host/api/v1/things/1