I am trying to make an API call using retrofit 2 in android for a given link. I am very new to making API calls.
Can someone help me with, from where should I start?
Check out an article like this, https://www.vogella.com/tutorials/Retrofit/article.html .
Overall, Retrofit is very straight forward once you get the hang of it.
All you really need to do is create an interface
for your API call and create a model for the response.
public interface GerritAPI {
@GET("changes/")
Call<List<Change>> loadChanges(@Query("q") String status);
}
And then call the API using the Retrofit
client.
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
GerritAPI gerritAPI = retrofit.create(GerritAPI.class);
Call<List<Change>> call = gerritAPI.loadChanges("status:open");
call.enqueue(this);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.