Hear is my API: http://v2sgroups.in/Erp_V2s_Groups/AndroidPanel/OTPVerification/099567. I try to call Api through retrofit framework , how can I pass parameter in retrofit like above link. 099657 is the passing parameter.
@GET("/AndroidPanel/OTPVerification/")
void otp(@Field("otp") String otp,
Callback<OTP> callback);
how to pass 099567 in using interface?
Its a path, you can do:
@GET("/AndroidPanel/OTPVerification/{otp}")
void otp(@Path("otp") String otp,
Callback<OTP> callback);
You can pass parameter by @QueryMap Retrofit uses annotations to translate defined keys and values into appropriate format. Using the @Query("key") String value annotation will add a query parameter with name key and the respective string value to the request url .
public interface API{
@POST("media-details")
retrofit2.Call<MediaDetails>getMediaList(@QueryMap Map<String, String> param);
}
private void getData() {
Map<String, String> data = new HashMap<>();
data.put("id", "12345");
data.put("end_cursor", "00000");
Call<MediaDetails> mediaDetails = ServiceAPI.getService().getMediaList(data);
mediaDetails.enqueue(new Callback<MediaDetails>() {
@Override
public void onResponse(Call<MediaDetails> call, Response<MediaDetails> response) {
}
@Override
public void onFailure(Call<MediaDetails> call, Throwable t) {
System.out.println("Failed");
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With