Developer Cafe

webClient를 사용해 API호출하기, Get하기 본문

Spring/WebClient

webClient를 사용해 API호출하기, Get하기

개발자 카페 2021. 5. 4. 17:28
728x90

www.baeldung.com/webflux-webclient-parameters

 

WebClient Requests with Parameters | Baeldung

Learn how to reactively consume REST API endpoints with WebClient from Spring Webflux.

www.baeldung.com

 

1. 간단하게 String으로 출력해보기

String result = WebClient.create("https://api.dev.zzimcar.co.kr")
                .get()
                .uri("/review/list?getCnt=10&sp=0")
                .retrieve()
                .bodyToMono(String.class)
                .block();

        System.out.println(result);

결과화면

2. Dto에 담아서 출력하기

ReviewResDto result = WebClient.create("https://api.dev.zzimcar.co.kr")
                .get()
                .uri("/review/list?getCnt="+pageSize+"&sp="+sp)
                .retrieve()
                .bodyToMono(ReviewResDto.class)
                .block();

        System.out.println(result);
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ReviewResDto {
    private int totalCnt;
    private List<ReviewDto> list;
}

@Data
class ReviewDto {
    private String agencyCode;
    private Integer bookingPid;
    private String carClass;
    private String companyid;
    private boolean direct;
    private String erpCode;
    private Integer getCnt;
    private Integer memberPid;
    private Integer pid;
    private boolean publish;
    private String sort;
    private Integer sp;
    private String zone;
    private String review;
    private int grade;
    private LocalDateTime regDtime;
}

결과화면

728x90

'Spring > WebClient' 카테고리의 다른 글

WebClient bodyToFlux  (0) 2021.05.11
webClient를 사용해 API호출하기, Post하기 .block() 의미  (0) 2021.05.07
Comments