API Platform CRUD
Parse Hydra collections and build API Platform pagination, order, search, and filter query strings.
page=2&itemsPerPage=15&order%5Btitle%5D=asc&order%5Bid%5D=desc&search=foundation&status%5B%5D=published&status%5B%5D=draft&published=true
Installation
npx shadcn@latest add https://ui.uptoolkit.com/r/api-platform-crud.jsonUsage
Helpers for API Platform collection endpoints. Parses
hydra:member / hydra:totalItems responses and builds query strings from
table state.
import {
buildApiPlatformQuery,
fetchApiPlatformCollection,
parseApiPlatformCollection,
withApiPlatformQuery,
} from "@/lib/api-platform-crud";
const query = buildApiPlatformQuery({
page: 1,
itemsPerPage: 20,
sort: [{ id: "title", desc: false }],
filters: [{ id: "status", operator: "in", value: ["published"] }],
search: "dune",
});
// page=1&itemsPerPage=20&order[title]=asc&status[]=published&search=dune
const collection = await fetchApiPlatformCollection<Book>("/api/books", {
page: 2,
itemsPerPage: 10,
sort: [],
filters: [],
});Defaults
| Parameter | Query key |
|---|---|
| Page | page |
| Page size | itemsPerPage |
| Sort | order[field]=asc|desc |
| Search | search |
Override names via ApiPlatformCrudConfig when your API uses custom parameter
names.