Corey Alix
Corey Alix

Reputation: 2750

ServiceStack Query String Mappings

I'm curious if it is possible to modify the servicesstack Route mapping rules. I'd like non-query string parameters to go in one area of the model and the query string parameters to go into another.

Specifically, I have this Route:

[Route("/gis/services/{Folders*}/{ServiceName}/{ServiceType}/{LayerId}/query", HttpMethods.Get)]
public class Model : Envelope<Request>
{
}

And the Envelope is defined like this:

    public class Envelope<T>
    {
        public string Folders { get; set; }
        public string ServiceType { get; set; }
        public string ServiceName { get; set; }
        public int LayerId { get; set; }
        public T Payload { get; set; }
    }

How can I map the query string parameters into the Payload and have everything else (Folders, ServiceType, ServiceName, LayerId) map as it normally would?

Upvotes: 1

Views: 292

Answers (1)

mythz
mythz

Reputation: 143319

Only the path info of the request are defined in ServiceStack Routes, all other properties can be populated by other Request Params like QueryString or Request Body.

Issues with your Routes

  • You should also only be using WildCard mappings like {folders*} at the end of Routes to avoid ambiguity.
  • Routes should match the Exact Property Name that's on the DTO, e.g. {ServiceName}
  • For maximum interoperability your Request DTO should be flat and not have any complex type properties populated via QueryStrings for which there is no standard
  • Your Request DTO is used to define your Service Contract which we recommend against trying to DRY or hide behind inheritance
  • Don't use the Service name for Request DTOs which is used for your Services implementation classes

Upvotes: 2

Related Questions