Reputation: 3294
I receive (Step 1) a soapString from a server and I would like to forward (Step 2) this String to another server.
public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/services/step2/forwardSoap")
Observable<String> order(@Body SoapString soapString);
}
In this case above, the afgter my.server.com which is "/webservices/step2/forwardSoap" is constant always. How can I make this part variable?
The trick here is, that the second server (for step 2) is specified in the response of the first reponse.
EDIT: Now, I use the proposal from @Tabish Hussain
public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/{urlPath}")
Observable<String> order(@Body SoapString soapString, @Path("urlPath") String urlPath);
}
and then I call
restAdapter.create(StepTwoRestAdapter.class).order(new TypedString(soapString), uriPath)
whereas my uriPath is "services/step2/forwardSoap"
But retrofit then calls: https://my.server.com/services%2Fstep2%2FforwardSoap
As you can see '/' was replaces by "%2F"
Upvotes: 5
Views: 10650
Reputation: 2434
Check this links, you should be able to find answer there:
https://futurestud.io/tutorials/retrofit-2-how-to-use-dynamic-urls-for-requests https://futurestud.io/tutorials/retrofit-2-how-to-change-api-base-url-at-runtime-2
I think the easiest way is:
public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST
Observable<String> order(@Url String url, @Body SoapString soapString);
}
If you are using Retrofit 1 check this one:
https://medium.com/@kevintcoughlin/dynamic-endpoints-with-retrofit-a1f4229f4a8d#.7atwl0o3t
Upvotes: 6
Reputation: 852
Do it like this
public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/services/{soapString}/forwardSoap")
Observable<String> order(@Path("soapString") SoapString soapString);
}
Upvotes: 7