How to send a HTTP-delete with a body in retrofit?

后端 未结 6 1245
暖寄归人
暖寄归人 2020-12-14 01:44

When I try to create a delete method:

public interface ImageService {
    @DELETE(\"api/v1/attachment\")
    Call delete(@Body DeleteMode         


        
6条回答
  •  误落风尘
    2020-12-14 02:11

    Originally answered here : https://stackoverflow.com/a/62920127/8956093

    Kotlin Code :

    path is not required if your first argument to interface method is a url annotated with @Url Example :

    @HTTP(method = "DELETE", hasBody = true)
    fun deleteStudentFromDatabase(
        @Url url: String,
        @Body payload: StudentModel
     ): Observable
    

    If first argument to interface method is not a url then use this

        @HTTP(method = "DELETE", path = "{urlPath}", hasBody = true)
        fun deleteStudentFromDatabase(
            @Body payload: StudentModel,
            @Path("urlPath") url: String
         ): Observable
    

提交回复
热议问题