14

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?

Sandah Aung
  • 6,156
  • 15
  • 56
  • 98
  • Possible duplicate of [How can I handle empty response body with Retrofit 2?](https://stackoverflow.com/questions/33228126/how-can-i-handle-empty-response-body-with-retrofit-2) – animalito maquina Sep 19 '19 at 11:49

2 Answers2

37

Just set Void as the Type.

@DELETE("/members/{id}")
Call<Void> removeMember(@Path("id") Long id);
sorianiv
  • 4,845
  • 1
  • 23
  • 27
1

If you are using Kotlin/Retrofit/Rxjava/RxKotlin

@Headers(JwtKeyTokenWithValue)
@DELETE("/members/{id}")
fun removeMember(@Path("id") Long id): Completable

And can be subscribed this way

apiManager
       .removeMember()
       .subscribe(
           { Timber.i { "Member Removed!" } },
           { t -> Timber.e(t)})
MetaPlanet
  • 129
  • 4