0
0

RestClientのDELETEリクエストでリクエストボディを使用する方法

Last updated at Posted at 2024-02-25

概要

Spring FrameworkでREST APIの呼び出しでDELETEメソッドにリクエストボディを使用する方法です。

Rest Clientのサンプル

Rest Clientの公式ページには以下のような3種類のサンプルがあります。
(RestTemplate から RestClient への移行)

restClient
    .delete()
    .uri(String, Object…​)
    .retrieve()
    .toBodilessEntity()
restClient
    .delete()
    .uri(String, Map)
    .retrieve()
    .toBodilessEntity()
restClient.
    .delete()
    .uri(URI)
    .retrieve()
    .toBodilessEntity()

このいずれの方法でもDELETEにリクエストボディを付与することができませんでした。
(パスパラメータに変数を設定するメソッドのようです)

解決した方法

以下のような方法で解消しました。

restClient
    .method(HttpMethod.DELETE)
    .uri(URI)
    .body(requestBodyMap)
    .retrieve()
    .toBodilessEntity()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0