'How to delete with Body using retrofit with usecase?

It is impossible to send request @DELETE with @BODY the only correct way which is accepted is @POST

I have found advice to use this sequence.

@HTTP(method = "DELETE", path = "account/firebase", hasBody = true)
fun deleteToken(@Body body: TokenChangedBody)

when using:

    fun notifyNotificationTokenChanged(token: String) {
        val params = DeleteTokenSecondUseCase.Params(token)
        deleteTokenSecondUseCase.build(params)
            .launchIn(viewModelScope)
    }

error:

  Process: com.example, PID: 18138
    java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)
        for method NotificationApi.deleteToken
        at retrofit2.Utils.methodError(Utils.java:54)
    fun notifyNotificationTokenChanged(token: String) {
        val params = DeleteTokenSecondUseCase.Params(token)
        deleteTokenSecondUseCase.buildWithState(params)
            .withSuccess { Log.d("build", "WORKS $params") }
            .withError {  Log.d("build", "NOT WORKS $params")  }
            .launchIn(viewModelScope)
    }

Nothing hapenn, no error, no information on chucker, no logs about it when I debug it only it goes with .withError gives me "NOT WORKS with $ my token".

enter image description here

enter image description here

I have two major questions:

  1. How to handle delete with @Body properly?
  2. How to write proper UseCase with @Delete?

I will make my best, thank for advice.

This is my @Post UseCase and works perfectly.

class NotifyBackendTokenChangedUseCase @Inject constructor(private val api: NotificationApi) :
    BaseApiRequestUseCase<NotifyBackendTokenChangedUseCase.Params, Unit>() {

    override fun create(params: Params) = flowSingle {
        api.notifyTokenChanged(NotificationApi.TokenChangedBody(params.token))
    }

    data class Params(val token: String)
}

EDIT 1: I have tested also in that approach:

    fun notifyNotificationTokenChanged(token: String) {
        val params = DeleteTokenSecondUseCase.Params(token)
        viewModelScope.launch { deleteTokenSecondUseCase.build(params) }
    }

class DeleteTokenSecondUseCase @Inject constructor(private val api: NotificationApi) :
    BaseUseCase<DeleteTokenSecondUseCase.Params, Unit>() {
    override suspend fun create(params: DeleteTokenSecondUseCase.Params) {
        api.deleteToken(NotificationApi.TokenChangedBody(params.token))

    }

    data class Params(val token: String)
}

error crash

    java.lang.IllegalArgumentException: Service methods cannot return void.
        for method NotificationApi.deleteToken


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source