retrofit android post example

Example 1: android retrofit post json example

Follow these steps:

1.) Firstly create modal class (MyRequestClass) for your Post request from http://www.jsonschema2pojo.org/

2.) Also create modal (MyResponseClass) for your server response from same site.

3.) Set values you want to send to your server by creating object of MyRequestClass.

4.) Then hit api using this method in your interface:

@POST("/provider/filter")
Call<MyResponseClass> sendDataToServer(@Body MyRequestClass myModal);

Example 2: how to use retrofit in android

package info.androidhive.retrofit.rest;
 
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
 
 
public class ApiClient {
 
    public static final String BASE_URL = "http://api.themoviedb.org/3/";
    private static Retrofit retrofit = null;
 
 
    public static Retrofit getClient() {
        if (retrofit==null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }
}

make a retrofit instance

Tags:

Java Example