Usage Examples

Examples of how to consume the auto-generated APIs.

Create a Record

const user = await $fetch("/api/users", {
  method: "POST",
  body: {
    name: "Cliford Pereira",
    email: "clifordpereira@gmail.com",
    bio: "Full-Stack Developer",
  },
});

Get All Records

const users = await $fetch("/api/users");

Get Record by ID

const user = await $fetch("/api/users/1");

Update a Record

const updated = await $fetch("/api/users/1", {
  method: "PATCH",
  body: {
    bio: "Updated bio",
  },
});

Delete a Record

await $fetch("/api/users/1", {
  method: "DELETE",
});

Note: If authentication is enabled (default):

  • Fullstack App: The module integrates with nuxt-auth-utils, so session cookies are handled automatically.
  • Backend-only App: You must include the Authorization: Bearer <token> header in your requests.