Documentation

Resources

Group related endpoints under stable domain names such as users, auth, products, or orders.

Endpoint groups

Resources

After you create an API client, the next step is to group endpoints into resources.

A resource is usually one domain in your app, such as users, auth, products, or orders.

Put endpoints that belong to the same domain inside the same resource.

The resource name is also used in generated query keys, so keep it short and stable.

Key points

  • Use stable names like users, auth, orders, or products.
  • Do not put IDs, filters, dates, or user-specific values in the resource name.
  • A resource can contain both read endpoints and write endpoints.
  • The returned resource is typed, so its helpers keep the endpoint inputs and outputs connected.
TypeScript
1export const users = api.resource("users", {2  list: api.get<User[]>("/users"),3  detail: api.get<User, string>((id) => `/users/${id}`),4  create: api.post<User, CreateUserDto>("/users"),5  update: api.patch<User, UpdateUserDto>(({ id }) => `/users/${id}`),6  remove: api.delete<void, string>((id) => `/users/${id}`),7});