Carlos Mendes - 214 - Oct 26, 2014


Is there a way to get the URL for a Route without replacing the place-holders?

For the following RequestDto I want to get: “/spaces/{spaceId}/analytics/users/{from}/{to}” 

[Route("/spaces/{spaceId}/analytics/users/{from}/{to}", HttpMethods.Get)]
public class GetUsersAnalyticsPage : IReturn<GetUsersAnalyticsPageResponse>
public long From { get; set; }
    public long To { get; set; }
    public int SpaceId { get; set; }

Thanks in advance

Carlos Mendes:

This seems to work


Carlos Mendes:

Thank you Demis.

Is there a way to get it without being in the context of a request to the Route?

I need something similar to the ToGetUrl extension method since I need to pass these ‘raw’ routes to my client side app and handle URL substitutions there.

Yeah you can get it from the IRequest:

var routePath = base.Request.GetRoute().Path;

Yeah that’s how you can query the Route attribute defined on the Request DTO, whereas req.GetRoute() returns the Route that was matched for the current request, it’s only available on the Request and not statically.

FYI, you can also get metadata about each operation (inc Route info) with the /operations/metadata route, e.g:

also available in other formats, e.g JSON:

Carlos Mendes:

Thanks. I wasn’t aware of the operations metadata endpoint.

There’s always “one more thing” in SS :slight_smile:

Yep no worries, it’s linked from the bottom of the metadata page under Debug Info: