API Features

The APIFeatures class represents a utility for manipulating and filtering API queries. It provides methods for filtering, searching, limiting fields, paginating, and sorting query results.

The APIFeatures class is used internally by the defineEventHandler function to implement the filter, search, sort, limitFields, and paginate methods.

server/api/users.get.ts
import { APIFeatures } from '#nuxt-server-utils'
import { User } from "~~/server/models/User.model";

export default defineEventHandler(async (event) => {

  const query = getQuery(event);

  const features = new APIFeatures(User.find(), query)
    .filter()
    .search()
    .sort()
    .limitFields()
    .paginate();

  const users = await features.query;

  reutrn users;
})