I want to perform DELETE using feign:
public static <T> T createClient(Class<T> type) {
return Feign.builder()
.client(new OkHttpClient())
.encoder(new GsonEncoder())
.decoder(new CustomGsonDecoder())
.logger(new Slf4jLogger(type))
.logLevel(Logger.Level.FULL)
.target(type, url);
}
Method from ConsumersClient interface:
@RequestLine("DELETE /consumers/{id}")
@Headers({"Content-Type: application/json", "Authorization: Bearer {token}"})
Response deleteConsumerById(@Param("token") String token, @Param("id") String id);
And when I do:
CLIENT = createClient(ConsumersClient.class);
CLIENT.deleteConsumerById(token, id)
And I got
{"statusCode":415,"error":"{\"timestamp\":\"2020-02-27T08:09:33.634Z\",\"status\":415,\"error\":\"Unsupported Media Type\",\"message\":\"Content type '' not supported\",\"path\":\"/consumers/id\"}"}
Since the message is: ""Content type '' not supported" I assume that Feign doesn't apply Content-Type value to its headers.
PLEASE NOTE: Same request via Postman returns 200 with the same parameters. So the service is working as expected.
Logback says the headers are included:
11:09:32.660 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] ---> DELETE https://hereGoesMyURL/consumers/id HTTP/1.1
11:09:32.663 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] Content-Type: application/json
11:09:32.663 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] Authorization: Bearer hereGoesTheToken
11:09:32.664 [main] DEBUG ConsumersClient - [ConsumersClient#deleteConsumerById] ---> END HTTP (0-byte body)
Please help to figure out what's wrong with my code.