Further reading
With the help of custom annotations inside the Retrofit interface, this library hides most of the complexity associated with handling network requests. We've seen that with simple GET
requests in our RestaurantsApiService
interface when we annotated our request with the @GET
annotation:
interface RestaurantsApiService { @GET("restaurants.json") fun getRestaurants(): Call<List<Restaurant>> }
Yet apart from plain GET
operations, such Retrofit interfaces can also handle other request types, such as PUT,
POST
, and DELETE
.
For example, if you need to define a request that passes some data to the server that is likely to be stored, you can use a POST
request by adding the @POST
annotation to your desired method:
@POST("user/edit") fun updateUser(@Field("first_name") firstName: String): Call<User>
To understand how to use Retrofit for...