Can I specify a query parameter in a route?

I have a service defined as follows:

[Route("/csv/forward/{QuoteDate}", "GET")]
public class GetCsvForward : IGet, IReturn<GetCsvForwardResponse>
{
    public string QuoteDate { get; set; } = "";  
}

The problem is that the endpoint (an external service) requires the QuoteDate to be a specified as a query parameter, such as

/csv/forward?2020-08-20

instead of

/csv/forward/2020-08-20

So, I am I able to specify this as a query parameter in the Routing, or am i being totally wrong with my approach?

No the route is only for defining the Route’s /path/info all QueryString or Form parameters are automatically used to further populate the the Request DTO. For the ?2020-08-20 format as you wont have that property on the Request DTO you’ll need to inspect the base.Request.QueryString collection for any additional keys.

I solved the problem by removing the route containing the QuoteDate and adding a route upto where the query parameter is required.

This create the url syntax I needed: csv/forward?quoteDate=2020-05-01

[Route("/csv/forward", "GET")]
public class GetCsvForward : IGet, IReturn<GetCsvForwardResponse>
{
    public string QuoteDate { get; set; } = "";  
}

Once again, highly impressed with ServiceStack.

1 Like