0Pricing
AI Powered SaaS: Stripe + Auth + Billing + Deploy · 강의

API 페이지 매김·필터링·정렬

대규모 데이터 집합을 페이지 단위로 반환하고 클라이언트가 결과를 필터링하고 정렬할 수 있게 하며 일관된 쿼리 매개변수를 제공해 SaaS API를 확장합니다.

API 페이지 매김·필터링·정렬은(는) CoddyKit의 무료 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 AI Powered SaaS: Stripe + Auth + Billing + Deploy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Not Return Everything?

An endpoint that returns 50,000 rows is slow, heavy, and crashes clients. Pagination returns data in manageable chunks, while filtering and sorting let clients ask for exactly what they need.

Offset Pagination

The simplest approach uses page and limit. You skip (page - 1) * limit rows and take limit rows.

GET /api/users?page=2&limit=20

Implementing Offset in Prisma

Prisma exposes skip and take for offset pagination.

const users = await prisma.user.findMany({
  skip: (page - 1) * limit,
  take: limit
});

Returning Metadata

Clients need to know how many pages exist. Return the data plus a total count and computed page info.

const total = await prisma.user.count();
return Response.json({
  data: users,
  page,
  totalPages: Math.ceil(total / limit)
});

The Offset Problem

Large offsets are slow because the database still scans skipped rows, and inserts can shift items between pages. For big or live datasets, prefer cursor pagination.

Cursor Pagination

A cursor points to the last item seen. The next request fetches rows after that cursor — fast and stable even as data changes.

const users = await prisma.user.findMany({
  take: limit,
  skip: 1,
  cursor: { id: lastId },
  orderBy: { id: 'asc' }
});

Filtering by Query Params

Read filter params from the URL and build a where clause. Use contains for search-style filters.

const q = searchParams.get('search');
const where = q ? { name: { contains: q, mode: 'insensitive' } } : {};

Combining Multiple Filters

Build the where object conditionally so only provided params apply. Prisma combines them with AND by default.

const where = {};
if (status) where.status = status;
if (minPrice) where.price = { gte: Number(minPrice) };

Sorting Safely

Accept a sort field and direction, but whitelist allowed fields so clients cannot order by arbitrary or sensitive columns.

const allowed = ['name', 'createdAt', 'price'];
const field = allowed.includes(sort) ? sort : 'createdAt';
const orderBy = { [field]: dir === 'desc' ? 'desc' : 'asc' };

Validating Query Params

Coerce and clamp inputs: cap limit so a client cannot request a million rows, and default page to 1.

const limit = Math.min(Number(searchParams.get('limit')) || 20, 100);
const page = Math.max(Number(searchParams.get('page')) || 1, 1);

Best Practices

Design scalable list endpoints:

  • Always paginate large collections
  • Use cursor pagination for big or live data
  • Return metadata (total, pages)
  • Whitelist sort fields and clamp limits

Quick Check

Test your pagination knowledge.

Recap

You learned to build scalable list APIs:

  • Paginate with skip/take or cursors
  • Return total and page metadata
  • Build dynamic where clauses for filtering
  • Whitelist sort fields and clamp the limit

Your API now handles large datasets efficiently.

자주 묻는 질문

“API 페이지 매김·필터링·정렬” 강의는 무료인가요?

네 — “API 페이지 매김·필터링·정렬” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의 전체를 잠금 해제할 수 있습니다. AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에는 총 4개의 강의가 포함되어 있습니다.

“API 페이지 매김·필터링·정렬”에서 뭘 배우나요?

대규모 데이터 집합을 페이지 단위로 반환하고 클라이언트가 결과를 필터링하고 정렬할 수 있게 하며 일관된 쿼리 매개변수를 제공해 SaaS API를 확장합니다. 브라우저에서 직접 실행하는 실습 코드로 AI Powered SaaS: Stripe + Auth + Billing + Deploy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

AI Powered SaaS: Stripe + Auth + Billing + Deploy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 AI Powered SaaS: Stripe + Auth + Billing + Deploy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“API 페이지 매김·필터링·정렬” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 AI Powered SaaS: Stripe + Auth + Billing + Deploy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. RESTful API 설계 원칙
  2. 데이터베이스 스키마 및 ORM
  3. 첫 API 엔드포인트
  4. API 페이지 매김·필터링·정렬
← AI Powered SaaS: Stripe + Auth + Billing + Deploy(으)로 돌아가기