I'm trying to send a request to a third party api using this DTO:
[Route("log_entries", "GET")]
public class MyRequest: IReturn<MyResponse>
{
}
The client request:
string uri = "https://..../api/v1"
var jsonClient = new JsonServiceClient(uri);
// This works
var response = client.Get<MyResponse>("/log_entries");
// Does not work
var response = client.Send(new MyRequest());
I'm getting a Not Found
response currently. When I send to http://
using Fiddler, I can see the
path /json/syncreply
is added i.e. ../api/v1/json/syncreply
> I am looking to understand where this comes from and how to ensure my request is sent on the right path.
Cheers
The /json/syncreply
is route that is defined in ServiceStack API, as a method for sending DTOs without having to provide a specific route for the given DTO, in other words a ServiceStack host would make a route based on the the type name of MyRequest
, which can be resolved by ServiceStack clients using the Send
method.
Send
As you are consuming a 3rd party API using the ServiceStack.JsonServiceClient
and their API is not ServiceStack based, then the Send
method will not work, because their server API does not have appropriate routes.
The Send
method only works for consuming ServiceStack API, because this is a ServiceStack specific feature.
You should be making your request like this, note the Get<T>
where T
is the request object, MyRequest
not MyResponse
.
MyResponse response = client.Get<MyRequest>();
And also add a slash at the front of your route declaration on your DTO:
[Route("/log_entries", "GET")]
public class MyRequest: IReturn<MyResponse>
{
}
For 3rd party API that is not a ServiceStack Service, you need to use the appropriate VERB methods such as Get
, Post
, Put
etc, so the route defined on the DTO is used, not the json/syncreply
route, therefore simply avoid the Send
method.