-2

I am creating a food booking App in Android.I need to send my order details which includes multiple product details and user details to back end which is created in P H P.I am using retrofit for web service calling.How to send these data in Json format to back end using retrofit.Do i need to create model class for saving data.

1 Answers1

1

In API Interface

@Headers("Content-Type:application/json")
@POST("auth/login")
Call<String> login(@Body RequestBody requestBody);

and when you make service call

JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put(Constants.Params.EMAIL, etEmail.getText().toString());
        jsonObject.put(Constants.Params.PASS_WORD, etPassword.getText().toString());


    } catch (JSONException e) {

    }

    ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
    final Call<String> loginCall = apiInterface.login(RequestBody.create(MediaType.parse("multipart/form-data"), jsonObject.toString));
Vishal G. Gohel
  • 1,008
  • 1
  • 16
  • 31