How to get the rest path of a request

hi SS

this is my scenario: SS 5.9.2 self hosted backend and classic net 4.8 framework

I have many RequestDTO classes decorated with the [Route] attribute. The route paths include placeholders like {id}, {context}, {tablename}, etc

I’m implementing a pre-request filter to validate requests against JSON schemas. What I’d like to do is use the API path to get the concrete DTO class type, pass that to an external library to retrieve the schema, and then validate the raw JSON request

in the pre-request filter context, I have access to the raw request body and the API path. However, the path has all placeholders replaced with actual parameter values.

since ServiceStack parses the [Route] attributes and substitutes the placeholders, I don’t want to reverse this process.
Is there a way to get the original [Route] value at runtime?

thanks

You can get the matching Route definition for the request from the IRequest.GetRoute() extension method, which will return an instance of RestPath although I’m not sure how useful it will be as it’s purpose is to create and Populate the Request DTO which you already have.

I don’t expect the request DTO to be populated, nor do I need to get it already populated.
I’m implementing a pre-request filter because it’s the first entry point in the ServiceStack pipeline, before request deserialization occurs

my goal is to read the original Path defined in the source code and via reflection to obtain the corresponding request DTO type

while debugging, I noticed these fields, which seem to be what I need

You can resolve the Route for the Request with:

var restPath = RestHandler.FindMatchingRestPath(httpReq, out var contentType);

And create a Request DTO from it with:

var requestDto = await RestHandler.CreateRequestAsync(httpReq, restPath);