# 데이터 페칭

## Route Handlers

Pages Router에 있던 API Routes의 App Router 버전입니다. `app` 디렉토리 아래 있는 어떤 폴더에서건 `route`라는 이름의 파일이라면 그건 API로 활용될 수 있습니다.&#x20;

Pages Router에서는 `api`라는 폴더 아래에 두고 API를 만들었는데 이제는 폴더 이름은 상관 없고 파일 이름이 `route` 이면 API가 될 수 있습니다.

<figure><img src="/files/NlIHGtkF0asrkeutYu8N" alt=""><figcaption><p>API Routes</p></figcaption></figure>

<figure><img src="/files/X3FZPZ8B7R7FKlbzqoEX" alt=""><figcaption><p>Route Handlers</p></figcaption></figure>

<figure><img src="/files/X0NNdDjyDU6mL08kzpZC" alt=""><figcaption><p>Route Handlers</p></figcaption></figure>

route라는 이름으로 만들어진 파일은 GET, POST 같은 메서드 이름으로 함수를 정의할 수 있습니다. 이 함수는 API가 호출됐을 때 동작합니다.

<figure><img src="/files/JIcF2GrpykTpaGRWnUMT" alt=""><figcaption><p>route.ts</p></figcaption></figure>

## Server Actions

`'use server'`라는 문장이 있는 **스코프**의 로직은 서버에서 동작합니다. 그게 설령 컴포넌트 안이라고 해도 가능합니다.

자세한 예시는 이후 Vercel 리더십 블로그에서 살펴볼 예정입니다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.hajoeun.dev/friendly-next-js/part-3-next.js/undefined-1/undefined-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
