Spring HTTP Client

前端 未结 3 1025
我在风中等你
我在风中等你 2021-01-31 02:11

I am new to Spring and I need my Java app to connect to another API over HTTP (JSON, RESTful). Does the Spring Framework have anything like a JSON HTTP Rest Client? What do Spri

3条回答
  •  误落风尘
    2021-01-31 02:28

    The simplest is to use the RestTemplate, check this article on the official Spring blog:

    The RestTemplate is the central Spring class for client-side HTTP access.

    This is an example of a GET:

    String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class, "42", "21");
    

提交回复
热议问题