Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a dynamic endpoint for retrofit POST call?

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"

like image 586
Ralf Wickum Avatar asked Dec 13 '16 14:12

Ralf Wickum


People also ask

Can you use multiple Baseurl in retrofit?

Yes, you can create two different Service instances.


1 Answers

Do it like this

public interface StepTwoRestAdapter {
    @Headers({"Content-Type:text/xml"})
    @POST("/services/{soapString}/forwardSoap")
    Observable<String> order(@Path("soapString") SoapString soapString);
}
like image 162
Tabish Hussain Avatar answered Oct 10 '22 17:10

Tabish Hussain