In Retrofit 2, service methods representing http methods must return Call
.
Call
is a generic which must take the type representing the return object of the http method.
For example,
@GET("/members/{id}")
Call<Member> getMember(@Path("id") Long id);
For http methods such as delete, no content is returned. In cases like this, what parameter should be provided to Call
?
You can just return a ResponseBody , which will bypass parsing the response. Even better: Use Void which not only has better semantics but is (slightly) more efficient in the empty case and vastly more efficient in a non-empty case (when you just don't care about body).
Retrofit is a REST Client for Java and Android allowing to retrieve and upload JSON (or other structured data) via a REST based You can configure which converters are used for the data serialization, example GSON for JSON.
Retrofit is a type-safe HTTP networking library used for Android and Java. Retrofit was even better since it was super fast, offered better functionality, and even simpler syntax. Most developers since then have switched to using Retrofit to make API requests.
Just set Void as the Type.
@DELETE("/members/{id}")
Call<Void> removeMember(@Path("id") Long id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With