Reverse Routing (of sorts)

I am not actually doing routing here, but I kind of need to reuse the reverse-routing built into ServiceStack.

Here is my problem, I am trying to populate a string that is a route, with the data in the current Request DTO.

  1. I have the IRequest

  2. The current DTO is defined like this:

    public class MyDto
    public string Id1{get;set;}
    public string Id2{get;set;}

I have a route string: “/resource/{Id1}/another/{Id2}/another” (not the same route as the MyDto

Assuming the current IRequest has an instance of the MyDto, I want to apply reverse routing, using the MyDto instance and the route above to yield this:

How do I do that using SS code?

Is this the recommend way:

        var populatedRoute = new RestRoute(Request.Dto.GetType(), "/resource/{Id1}/another/{Id2}/another", null, 0).FormatQueryParameters(Request.Dto);

I got this working (by examining the extension ToUrl()):

        var route = new RestRoute(Request.Dto.GetType(), pattern, @"PUT, DELETE", 0);
        return route.Apply(Request.Dto, null).Uri;

But affirmation that this is the right approach, would still be good.

There’s no formal API that explicitly does this, but internally this is what the Reverse Routing extension methods use.