SSR이 API endpoints 활성화한다.

endpoint를 만들기 위해서 .json.js로 끝나는 파일을 src/pages 폴더에 작성해 넣어야한다.

GET, POST 그리고 다른 HTTP methods를 지원해준다.

GET API endpoint를 GET functions를 exporting함으로써 구현할 수 있다

src/pages/todo.json.js

export const GET = async {{ params, request }} => {
	
}

export const GET = async ({ params, request }) => {
	return new Response(JSON.stringify([
		'Buy the milk',
		'Write a blog post'
	]))
}

에 적고 localhost:4321/todos.json 로 들어가면 GET 요청 가능

POST 요청은 다음과 같이 적고 요청하면 된다.

export const POST = async ({ request }) => {
	console.log(request.headers)
	console.log(await request.json())
	return new Response()
}