페이지 매김, 필터링 및 API 버전 관리
쿼리 페이지 매김, 유연한 필터링, 깔끔한 버전 관리 전략으로 Phoenix API를 확장 가능하고 유지 관리하기 쉽게 만드는 방법을 배웁니다.
페이지 매김, 필터링 및 API 버전 관리은(는) CoddyKit의 무료 Elixir & Phoenix: Scalable Backend Development 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Elixir & Phoenix: Scalable Backend Development 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Elixir & Phoenix: Scalable Backend Development 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Pagination Matters
Returning every record in one response is slow and memory-heavy. Pagination sends data in manageable pages.
Offset-Based Pagination
The classic approach uses limit and offset driven by query params like ?page=2&per_page=20.
from(p in Post, limit: ^per_page, offset: ^((page - 1) * per_page))Returning Page Metadata
Clients need to know totals. Include metadata such as current page, page size, and total count alongside the data.
%{
data: posts,
meta: %{page: 2, per_page: 20, total: 137}
}The Downside of Offset
Large offsets get slow because the database still scans skipped rows, and rows shifting between requests cause duplicates.
Cursor-Based Pagination
Cursor pagination uses the last seen value (often an id or timestamp) to fetch the next page, staying fast and stable.
from(p in Post,
where: p.id > ^cursor,
order_by: [asc: p.id],
limit: ^limit)Filtering Results
Let clients narrow results with query params. Build the query conditionally based on which params are present.
def filter(query, %{"status" => status}) do
from(q in query, where: q.status == ^status)
end
def filter(query, _), do: queryComposing Multiple Filters
Reduce over a params map to apply each supported filter, keeping the query composable and safe from injection via parameter binding.
Enum.reduce(params, base_query, fn
{"author", a}, q -> from(p in q, where: p.author == ^a)
_, q -> q
end)Sorting
Accept a sort param and map it to a safe whitelist of allowed columns to avoid arbitrary ordering.
order = case params["sort"] do
"newest" -> [desc: :inserted_at]
_ -> [asc: :id]
endWhy Version Your API?
Versioning lets you evolve the API without breaking existing clients when you change response shapes or behavior.
URL Path Versioning
The most common strategy puts the version in the path, scoped in the router.
scope "/api/v1", MyAppWeb.V1 do
pipe_through :api
resources "/posts", PostController
endHeader-Based Versioning
Alternatively, select the version from an Accept header so URLs stay stable. Choose ONE strategy and stay consistent.
# Accept: application/vnd.myapp.v2+jsonQuick Check
Test your API scaling knowledge.
Recap
You made APIs scalable and durable:
- Paginate with offset (simple) or cursor (fast, stable)
- Return page metadata with the data
- Apply composable, parameter-bound filters and whitelisted sorting
- Version via URL path or Accept header, consistently
AI 튜터와 함께 Elixir을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 12
- 레슨
- 48
자주 묻는 질문
“페이지 매김, 필터링 및 API 버전 관리” 강의는 무료인가요?
네 — “페이지 매김, 필터링 및 API 버전 관리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Elixir & Phoenix: Scalable Backend Development 강의 전체를 잠금 해제할 수 있습니다. Elixir & Phoenix: Scalable Backend Development 강의에는 총 4개의 강의가 포함되어 있습니다.
“페이지 매김, 필터링 및 API 버전 관리”에서 뭘 배우나요?
쿼리 페이지 매김, 유연한 필터링, 깔끔한 버전 관리 전략으로 Phoenix API를 확장 가능하고 유지 관리하기 쉽게 만드는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Elixir & Phoenix: Scalable Backend Development을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Elixir & Phoenix: Scalable Backend Development을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Elixir & Phoenix: Scalable Backend Development은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“페이지 매김, 필터링 및 API 버전 관리” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Elixir & Phoenix: Scalable Backend Development 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Elixir & Phoenix: Scalable Backend Development 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- API 설계 원칙과 모범 사례
- API 엔드포인트 구현과 직렬화
- 인증 및 권한 부여 전략
- 페이지 매김, 필터링 및 API 버전 관리