
이 글은 2026년 05월 28일 작성된 글입니다.
오늘은 Next.js 기반 프론트엔드 프로젝트를 세팅하고, Spring Boot REST API 서버와 연동하여 게시글 목록/상세/작성 기능을 구현했다.
또한 서버 컴포넌트와 클라이언트 컴포넌트의 차이, fetch 기반 데이터 요청, 환경변수 관리, 동적 라우팅 등을 학습했다.
npx create-next-app@latest
npm run dev
{
"tabWidth": 4,
"trailingComma": "all",
"semi": false,
"singleQuote": true
}
'use client'
| 구분 | 서버 컴포넌트 | 클라이언트 컴포넌트 |
|---|---|---|
| 상태관리 | 불가능 | 가능 |
| 이벤트 | 불가능 | 가능 |
| 렌더링 | 서버 | 브라우저 |
useEffect(() => {
fetch('http://localhost:8080/api/v1/posts')
.then((res) => res.json())
.then((data) => setPosts(data))
}, [])
src/app/posts/[id]/page.tsx
if (post == null) {
return <div>로딩중...</div>
}
return <div>{post.title}</div>
NEXT_PUBLIC_API_BASE_URL=http://localhost:8080
fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/posts`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: titleInput.value,
content: contentInput.value,
}),
})