0

In my application i need to consume a API which need to call with 2 different type of request.

if user adding employee i need to call with POST, while updating user i need to call with PUT.

For now i am able to construct request with dynamic URL, headers, request, but along with this i should be able to supply request type also.

@PUT
fun addorUpdateEmp(
    @Url url: String?, @HeaderMap headers: Map<String, String>?, @Body data: EmployeeModel.Request
): Call<EmployeeModel.Response>

Here i don't want to hard code "PUT" type, instead i want to supply that as parameter

Ashok Reddy Narra
  • 577
  • 10
  • 27
  • 1
    I think this is not possible, because Retrofit is using Annotations to declare the HTTP method in your Java Interface. As far as I know there is no solution to dynamically change annotations on runtime (see: https://stackoverflow.com/questions/10636201/java-annotations-values-provided-in-dynamic-manner) – NKnuelle Jan 03 '20 at 14:04
  • I don't know why do you wanna use this ugly approach. But anyway the only opportunity to do this is create PUT and POST method in api Interface and in the implementation layer like Client/Manager etc you could choose that to use with some param. – Eugene Troyanskii Jan 03 '20 at 14:13
  • Retrofit doesn't allow that approach. For me I have to work around by using the original `OkHttp` and manually setup the method, url, body, response ... – Tam Huynh Jan 03 '20 at 14:44

0 Answers0