Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit 2 void return

Tags:

retrofit2

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?

like image 436
Sandah Aung Avatar asked Feb 16 '16 10:02

Sandah Aung


People also ask

How do you handle an empty response in retrofit?

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).

What is Retrofit2?

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.

Why use Retrofit in Android?

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.


1 Answers

Just set Void as the Type.

@DELETE("/members/{id}")
Call<Void> removeMember(@Path("id") Long id);
like image 119
sorianiv Avatar answered Sep 17 '22 14:09

sorianiv