Q:

How to hit Firebase HTTP protocol with Retrofit?

I want o post data on https://fcm.googleapis.com/fcm/send
along with two headers in Retrofit
Data to be sent
{
  "data" : {
    "title": "My Title",
    "content": "My message"
  },

  "to": "cKA7LrjBQ6s:APA91bHtY6RBwZ4KZvxbl9VNZMVKz5_NDbE2dP3zgrhJNBSAKDyfOAbfxEi8pnAwc82pzLoGEZImZBv9MXvoBSJy6c0790oqUIYLECCU5WZVcGeSJJNECX5bsLMutYrSPjLSDffP5N3u"
}

A:

It's very simple. Create the following classes.
public interface RestInterface {

    @Headers({
        "Content-Type: application/json",
        "Authorization: key=<YOUR_FCM_SERVER_KEY_HERE>"
    })
    @POST("fcm/send")
    Call<ResponseBody> sendNotification(@Body NotificationBody body);

}

Replace <YOUR_FCM_SERVER_KEY_HERE> with your actual FCM server key.
public class NotificationBody {

    @SerializedName("data")
    private Data data;

    @SerializedName("to")
    private String to;

    public NotificationBody(Data data, String to) {
        this.data = data;
        this.to = to;
    }

}

Above POJO class will generate outer JSONObject in run-time. And the following POJO class will generate data JSONObject.
public class Data {

    @SerializedName("title")
    private String title;

    @SerializedName("content")
    private String content;

    public Data(String title, String content) {
        this.title = title;
        this.content = content;
    }

}

And finally use above code in your Activity/Fragment classes like below,
String title = "My Title";
String content = "My message";
String to = "cKA7LrjBQ6s:APA91bHtY6RBwZ4KZvxbl9VNZMVKz5_NDbE2dP3zgrhJNBSAKDyfOAbfxEi8pnAwc82pzLoGEZImZBv9MXvoBSJy6c0790oqUIYLECCU5WZVcGeSJJNECX5bsLMutYrSPjLSDffP5N3u";

Data data = new Data(title, content);
NotificationBody body = new NotificationBody(data, to);

RestInterface api = ....;

Call<ResponseBody> call = api.sendNotification(body);
call.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, final Response<ResponseBody> response) {

        // do whatever you want to do

    }

    @Override
    public void onFailure(Call<ResponseBody> call, Throwable t) {
        Log.e("TAG", "Error: ", t);
    }
});

And don't forget to set Retrofit BASE_URL to https://fcm.googleapis.com/ 

