Spring boot/Bank App

Server To Server 개념을 알아보자.

H_u 2024. 8. 16. 12:38
728x90
반응형
SMALL
💡 학습 목표

RestTemplate 사용 이유

RestTemplate은 Spring Framework에서 제공하는 HTTP 통신을 간편하게 처리할 수 있는 클래스입니다. org.springframework.web.client.RestTemplate 패키지에 존재 합니다.

RESTful 웹 서비스와의 통신을 위해 주로 사용되고 기본적으로 동기 방식으로 처리되며, 비동기 방식으로 처리하고 싶을 경우 AsyncRestTemplate를 사용하면 됩니다.

 

https://jsonplaceholder.typicode.com/

 

JSONPlaceholder - Free Fake REST API

{JSON} Placeholder Free fake and reliable API for testing and prototyping. Powered by JSON Server + LowDB. Serving ~3 billion requests each month.

jsonplaceholder.typicode.com

https://jsonplaceholder.typicode.com/

 

RestTemplate 대표적 메서드

RestTemplate Method HTTP Method 설명

getForEntity GET get 요청을 보내고 ResponseEntity로 응답을 받음
getForObject GET get 요청을 보내고 java object로 매핑받아서 반환받음
exchange Any 헤더 세팅해서 HTTP Method로 요청보내고 ResponseEntity로 반환받음
put PUT PUT 형식으로 요청
delete DELETE DELETE 형식으로 요청
postForLocation POST post 요청을 보내고 java.net.URI 로 반환받음
postForObject POST post 요청을 보내고 Object로 반환받음
postForEntity POST POST 방식으로 요청하면 ResponseEntity를 반환해 준다.
optionsForAllow OPTIONS 해당 URI에서 지원하는 HTTP 메서드를 조회
execute Any 요청과 응답에 대한 콜백 수정
728x90
반응형
SMALL