[데브코스] Spring Boot REST API 실습 (20강) – 글/댓글 다건·단건 조회 구현 & Postman 실습

zuno·2025년 12월 24일

이번 글에서는 Spring Boot REST API 실습 20강 내용을 정리한다.
그동안 구현해온 API를 Postman으로 직접 호출하며 검증해보는 단계다.

이번 강의의 핵심은

“프론트가 없어도 REST API는 충분히 검증할 수 있다”
라는 점을 체감하는 것이다.


1️⃣ 이번 강의에서 확인한 것

  • 글 다건 조회 API
  • 글 단건 조회 API
  • 댓글 다건 조회 API
  • 댓글 단건 조회 API
  • Postman을 이용한 API 호출 및 응답 확인

REST API 방식에서는
서버는 JSON 데이터만 책임지고,
화면과 UI는 프론트엔드의 몫이다.


2️⃣ 글 다건 조회 API

📌 요청

GET http://localhost:8080/api/v1/posts

📌 컨트롤러 코드

@GetMapping
@Transactional(readOnly = true)
public List<PostDto> getItems() {
    List<Post> items = postService.findAll();

    return items
            .stream()
            .map(PostDto::new)
            .toList();
}

📌 응답(JSON)


3️⃣ 글 단건 조회 API

📌 요청

GET http://localhost:8080/api/v1/posts/2

📌 컨트롤러 코드

@GetMapping("/{id}")
@Transactional(readOnly = true)
public PostDto getItem(@PathVariable int id) {
    Post post = postService.findById(id).get();
    return new PostDto(post);
}

📌 응답(JSON)


4️⃣ 댓글 다건 조회 API

📌 요청

GET http://localhost:8080/api/v1/posts/2/comments

📌 컨트롤러 코드

@GetMapping
@Transactional(readOnly = true)
public List<PostCommentDto> getItems(
        @PathVariable int postId
) {
    Post post = postService.findById(postId).get();

    return post.getComments()
            .stream()
            .map(PostCommentDto::new)
            .toList();
}

📌 응답(JSON)


5️⃣ 댓글 단건 조회 API

📌 요청

GET http://localhost:8080/api/v1/posts/2/comments/4

📌 컨트롤러 코드

@GetMapping("/{id}")
@Transactional(readOnly = true)
public PostCommentDto getItem(
        @PathVariable int postId,
        @PathVariable int id
) {
    Post post = postService.findById(postId).get();
    PostComment postComment = post.findCommentById(id).get();
    return new PostCommentDto(postComment);
}

📌 응답(JSON)


6️⃣ Postman으로 API를 테스트하는 이유

  • 프론트엔드 구현 전에도 API 검증 가능
  • 요청 / 응답 구조를 명확하게 확인 가능
  • 프론트 개발자와 API 스펙 공유가 쉬워짐

REST API 개발에서
Postman은 거의 필수 도구라고 봐도 무방하다.


🔚 정리

  • REST API는 화면이 아닌 JSON 데이터를 반환한다
  • 글 / 댓글 다건·단건 조회 API를 모두 구현했다
  • Postman을 통해 API가 정상 동작함을 직접 확인했다
  • 다음 단계에서는 작성 / 수정 / 삭제 API로 확장된다

💡 한 줄 요약

프론트가 없어도 REST API는
Postman만으로 충분히 검증할 수 있다.

0개의 댓글