Postman 을 μ‹œν–‰ν•œ 이후 처음 λ“±μž₯ν•˜λŠ” 화면이닀. μœ„μͺ½μ—λŠ” Request 에 λŒ€ν•œ 뢀뢄이며, μ•„λž˜μ—λŠ” Response 에 λŒ€ν•œ 뢀뢄이닀.

κ°„λ‹¨ν•œ test λ₯Ό μœ„ν•˜μ—¬ REST API λ₯Ό μ œκ³΅ν•˜λŠ” https://jsonplaceholder.typicode.com/ 을 μ‚¬μš©ν•΄λ³΄μž.

JSONPlaceholder Service μ—μ„œ μ œκ³΅ν•˜λŠ” API μ€‘μ—μ„œ, /users λ₯Ό μ‚¬μš©ν•˜μ—¬ ν…ŒμŠ€νŠΈν•œ 결과이닀. μš°μ„  HTTP Response Message μ—μ„œ ν™•μΈν–ˆλ“―μ΄, Body λΆ€λΆ„μ—μ„œ JSON ν˜•νƒœλ‘œ data κ°€ μ „λ‹¬λœ 것을 λ³Ό 수 μžˆλ‹€.

우츑 쀑단 λΆ€λΆ„μ—μ„œλŠ” 200 μ΄λΌλŠ” Successful Status Code κ°€ μ „λ‹¬λœ 것을 λ³Ό 수 있으며, Headers tab μ—μ„œ Content-Type, Date λ“±μ˜ data 에 λŒ€ν•œ metadata, 즉 λΆ€κ°€ 정보λ₯Ό 확인할 수 μžˆλ‹€.

Spring REST Controller

μ΄λ²ˆμ—λŠ” μ‹€μ œ Spring Boot Project μ—μ„œ REST Controller λ₯Ό λ§Œλ“  뒀에, Postman 을 μ΄μš©ν•˜μ—¬ request 와 response λ₯Ό test ν•΄λ³΄μž. μš°μ„  μœ„ μ΄λ―Έμ§€μ˜ ꡬ쑰λ₯Ό 기반으둜, κ°„λ‹¨ν•˜κ²Œ λ¬Έμžμ—΄μ„ 좜λ ₯ν•˜λŠ” Handler Method λ₯Ό ν•˜λ‚˜ μƒμ„±ν•˜μ—¬ REST API λ₯Ό λ§Œλ“€μ–΄λ³΄μž.

@RestController  
@RequestMapping("/test")  
public class DemoRestController {  
  
    @GetMapping("/hello")  
    public String sayHello() {  
        return "Hello World!";  
    }  
}

이제 Application 을 μ‹€ν–‰ν•˜κ³  Postman 에 GET method 둜 request λ₯Ό λ³΄λ‚΄λ³΄μž.

μœ„μ™€ 같이 "Hello World!" λΌλŠ” λ¬Έμžμ—΄μ΄ reponse message 의 body 뢀뢄을 ν†΅ν•˜μ—¬ 잘 μ „λ‹¬λœ 것을 λ³Ό 수 μžˆλ‹€.

이 μ •λ„λŠ” κ·Έλƒ₯ Google Chrome κ³Ό 같은 browser μ—μ„œλ„ ν•  수 μžˆλŠ”λ°, μ™œ Postman κ³Ό 같은 Client Tool 을 μ‚¬μš©ν•˜λŠ” κ²ƒμΌκΉŒ?

κ°„λ‹¨ν•œ GET request μ—μ„œλŠ” 차이점을 κ΅¬λ³„ν•˜κΈ° μ–΄λ ΅λ‹€. ν•˜μ§€λ§Œ POST, PUT λ“±κ³Ό 같은 λ³΅μž‘ν•œ HTTP Method λ₯Ό test ν•  λ•Œμ—λŠ” API test 에 ν•„μš”ν•œ κΈ°λŠ₯을 λ‹€μ–‘ν•˜κ²Œ μ œκ³΅ν•˜κΈ° λ•Œλ¬Έμ— νš¨μœ¨μ μ΄λ‹€.