I have a pre-defined (as in, I cannot modify) request DTO with a Route
already assigned to it, that looks soemthing like this:
[Route("/import", "POST")]
public class ImportEventsRequest : List<MixpanelEvent>, IReturn<ImportEventsResponse>, IPost
{
[DataMember(Name = "strict")]
public int Strict { get; set; }
[DataMember(Name = "project_id")]
public string ProjectId { get; set; }
}
(just so happens it is one that I use to make outbound calls to api.mixpanel.com from the back-end of my API, using a JsonServiceClient
).
Now, I want to re-use that request DTO in my own Stub API (used in testing), for which I have a AppHostBase
running in a console app.
In that testing stub console app, this is used instead of the internet, during testing) I have my own dedicated service, as we would expect, something like this:
public class StubMixpanel : StubServiceBase
{
public ImportEventsResponse Post(ImportEventsRequest request)
{
...stuff for logging for testing purposes....
Response.StatusCode = (int)HttpStatusCode.OK;
return new ImportEventsResponse
{
Code = 200,
NumRecordsImported = 1,
Status = "OK"
};
}
}
None of this is a challenge with ServiceStack.
When I stand up my stub testing console app, (on say https://localhost:5656
I now accept requests directly on the path /
(AppHost.HandlerFactoryPath=""
).
So, for the request above I would taking inbound requests to my testing stub on: https://localhost:5656/import
.
However, it is not what I want, since Mixpanel is just one of many integrations we have stubs for, and we occasionally have path collisions with other 3rd party services. I need to segregate the API’s of each 3rd party integration.
What I want to do is move my /import
path down to https://localhost:5656/mixpanel/import
and have all mixpanel API requests hang off this path /mixpanel
. Which won’t collide with other integrations.
What is a good way to do this seggregation in ServiceStack? in configuring the ServiceHost
(or Filters or whatever?), bearing in mind I have to re-path a ton of other APIs, without changing their declared [Route]
statements?
Ideally, it would be something I do per Service
class, since that represents the segregation.