Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass Parameter In retrofit

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?

like image 879
Payal Sorathiya Avatar asked Jan 04 '23 16:01

Payal Sorathiya


2 Answers

Its a path, you can do:

@GET("/AndroidPanel/OTPVerification/{otp}")
void otp(@Path("otp") String otp,
        Callback<OTP> callback);
like image 62
Saurabh Avatar answered Jan 19 '23 16:01

Saurabh


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");
            }
        });
    }
like image 22
sunil kumar Avatar answered Jan 19 '23 14:01

sunil kumar