Full CRUD
Manage the users of the docs backend with every HTTP method: create one, pick one to update or patch, or delete one.
ts
import { q } from "@/lib/query"
// List
const { data, refetch } = q.users.useQuery("getAll")
// Create
const create = q.users.useMutation("create", {
onSuccess: () => refetch(),
})
// Update (PUT — full replace)
const update = q.users.useMutation("update", {
onSuccess: () => refetch(),
})
// Patch (PATCH — partial update)
const patch = q.users.useMutation("patch", {
onSuccess: () => refetch(),
})
// Delete
const remove = q.users.useMutation("remove", {
onSuccess: () => refetch(),
})q.users — create · update · patch · removeSANDBOX
// run the request to see the responseIndividual Operations
Each operation on its own, and the endpoint it calls.
ts
// CREATE
const create = q.users.useMutation("create", {
onSuccess: () => refetch(),
})
create.mutate({ name: "New User", email: "new@example.com" })
// UPDATE (PUT)
const update = q.users.useMutation("update")
update.mutate({
id: 1,
name: "Updated Name",
email: "updated@example.com",
role: "moderator",
})
// PATCH
const patch = q.users.useMutation("patch")
patch.mutate({ id: 1, name: "Patched Name" })
// DELETE
const remove = q.users.useMutation("remove")
remove.mutate({ id: 1 })- POST
users:createcreates a user- PUT
users:updatereplaces the whole user- PATCH
users:patchchanges the fields given- DELETE
users:removedeletes the user