Payal Sorathiya
Payal Sorathiya

Reputation: 754

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?

Upvotes: 4

Views: 12433

Answers (2)

sunil kumar
sunil kumar

Reputation: 41

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");
            }
        });
    }

Upvotes: 4

Saurabh
Saurabh

Reputation: 1245

Its a path, you can do:

@GET("/AndroidPanel/OTPVerification/{otp}")
void otp(@Path("otp") String otp,
        Callback<OTP> callback);

Upvotes: 6

Related Questions