포스트맨을 사용하는 이유
프론트로 보여진는 부분을 만들지 않는다 -> 코드가 제대로 작동하는지 확인하기 어렵다.
-> 포스트맨을 사용하면 결과값을 불러와 코드가 잘 작동하는지 확인할 수 있다.
* 프론트, 백엔드를 각각 작업할 때 백엔드 작업이 먼저 끝나거나 백엔드 코드 동작 확인이 필요할 때 포스트맨을 사용해 코드를 확인한다.
사용방법
1. 코드작성하기
2. 실행하기
3. 포스트맨 접속 -> My Workspace
4. GET http://localhost:8080 Send
5. 작성한 API 확인 포스트맨 이용해서 확인하기
요약
POST : 내용을 함께 작성해야 함, Body, rqw, JSON
GET
PUT : 수정(변경)내용을 함께 작성해야 함, Body, raw, JSON
{id}") → {id} 값은 상수 값을 넣어준다( ex)메모 식별번호, 1번 메모를 수정하려면 /1를 작성)
DELETE : {id}") → {id} 값은 상수 값을 넣어준다( ex)메모 식별번호, 1번 메모를 삭제하려면 /1를 작성)
POST
// 메모생성하기 API
@PostMapping("/api/memos")
public Memo createMemo(@RequestBody MemoRequestDto requestDto) {
return memoService.createMemo(requestDto);
}
POST http://localhost:8080/api/memos Send
1 | @PostMapping → POST 선택
2 | @PostMapping("/api/memos") → http://localhost:8080/api/memos
3 | public Memo createMemo(@RequestBody MemoRequestDto requestDto) { } → Body / raw / JSON
1. @PostMapping → POST 선택
// 어노테이션 앞 부분에 맞춰 맞춰 POST, GET, PUT, DELETED 등 선택
// ex) @PostMapping → POST
2. @PostMapping("/api/memos") → localhost:8080/api/memos
// 기본 호스팅 주소에 작성한 API 넣기 → /api/memos
3. public Memo createMemo(@RequestBody MemoRequestDto requestDto) {
return memoService.createMemo(requestDto);
} → Body / raw / JSON
// 어노테이션 맞춰서 Body선택, JSON 방식 선택
// ex) @RequestBody → Body 선택, 백엔드에서는 거의 JSON으로 반환한다고 생각하면 됨
// @RequestParams → Params 선택
이렇게 작성하고 Send 누르면 오류 촤라락
메모를 생성하는 API를 메모생성 없이 서버응답을 확인했으니 오류가 발생
메모를 생성하고 서버가 제대로 응답하는지 테스트를 진행해야함 → 포스트맨을 사용하는 이유★
{
"username": "hi",
"contents": "111"
}
메모 생성에 필요한 값은 username, contents 2개
2개 값을 입력한 후 Send 로 서버응답 확인하기
그러면 이렇게 제대로 응답하는지 확인 가능!
GET
//메모조회하기
@GetMapping("/api/memos")
public List<Memo> getMemos() {
return memoService.getMemos();
}
GET http://localhost:8080/api/memos Send
1 | @GETMapping → GET 선택
2 | @GetMapping("/api/memos") → http://localhost:8080/api/memos
3 | public List<Memo> getMemos() {return memoService.getMemos();}→ Body / none∙raw
: none, raw어떤걸 선택해야되는지는 다시 공부해봐야할 것 같다(둘다 메모조회는 가능했음)
PUT
//메모변경하기
@PutMapping("/api/memos/{id}")
public Long updateMemo(@PathVariable Long id, @RequestBody MemoRequestDto requestDto) {
return memoService.update(id, requestDto);
}
PUT http://localhost:8080/api/memos Send
1 | @PutMapping → PUT 선택
2 | @PutMapping("/api/memos/{id}") → http://localhost:8080/api/memos/상수
3 | public Long updateMemo(@PathVariable Long id, @RequestBody MemoRequestDto requestDto) {
return memoService.update(id, requestDto);} → Body / raw / JSON
POST와 마찬가지로 수정(변경)할 내용을 작성한 후 Send
@PutMapping("/api/memos/{id}") → {id} 값은 상수 값을 넣어준다( ex)메모 식별번호, 1번 메모를 수정하려면 /1를 작성)
잘 수정되었는지 GET을 통해 확인(전체 메모 리스트 조회)
1번 메모가 수정되어 있는 것 확인 가능
DELETE
// 메모삭제하기
@DeleteMapping("/api/memos/{id}")
public Long deleteMemo(@PathVariable Long id) {
return memoService.deleteMemo(id);
}
DELETE http://localhost:8080/api/memos Send
1 | @DeleteMapping → DELETE 선택
2 | @GetMapping("/api/memos/{id}") → http://localhost:8080/api/memos/상수
3 | public Long deleteMemo(@PathVariable Long id) {return memoService.deleteMemo(id);}→ Body / none∙raw
: none, raw어떤걸 선택해야되는지는 다시 공부해봐야할 것 같다(둘다 메모조회는 가능했음)
1번 메모 삭제하기!
GET을 통해 전체 메모리스트를 조회해보면 1번 메모가 없는 것을 확인 가능하다.
POST, GET, PUT, DELETE API 확인 방법 정리 끝~!