Building Type-Safe APIs with Nuxt 3 and Prisma
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Practical API design guidelines covering naming conventions, error handling, pagination, and versioning for RESTful services.
Mbeah Essilfie
June 25, 2026 at 06:03 AM
An API is a UI for developers. The same principles apply: consistency, discoverability, and helpful error messages.
✅ GET /api/posts — List posts
✅ GET /api/posts/:id — Get a post
✅ POST /api/posts — Create a post
✅ PATCH /api/posts/:id — Update a post
✅ DELETE /api/posts/:id — Delete a post
❌ GET /api/getPost/:id — Don't use verbs in URLs
❌ POST /api/posts/create — The HTTP method IS the verb
❌ GET /api/post/:id — Use plural nouns
// Success response
{
"success": true,
"data": { ... },
"meta": {
"page": 1,
"limit": 20,
"total": 156
}
}
// Error response
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input",
"details": [
{ "field": "email", "message": "Must be a valid email" }
]
}
}
// Offset-based (simple, supports jumping to pages)
GET /api/posts?page=2&limit=20
// Cursor-based (better performance at scale)
GET /api/posts?cursor=abc123&limit=20
GET /api/posts?status=published&sort=-publishedAt&tags=vue,nuxt
Convention: prefix with - for descending sort.
Return appropriate HTTP status codes:
// server/utils/errors.ts
export function notFound(resource: string) {
throw createError({
statusCode: 404,
message: `${resource} not found`,
data: { code: 'NOT_FOUND' },
})
}
export function validationError(errors: ValidationError[]) {
throw createError({
statusCode: 422,
message: 'Validation failed',
data: { code: 'VALIDATION_ERROR', details: errors },
})
}
For most APIs, URL versioning is simplest:
/api/v1/posts
/api/v2/posts
But consider: do you actually need versioning? For internal APIs (your own frontend), evolve the API in place and update both sides together.
Always communicate limits:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 87
X-RateLimit-Reset: 1625097600
Good API design is: consistent naming, predictable responses, helpful errors, and clear documentation. Make it obvious, then make it fast.
Fullstack Software Developer
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Go beyond basic utility classes and learn how to build cohesive, maintainable design systems with Tailwind CSS.
Understand the power of Vue 3's Composition API through practical, real-world composable patterns that you can use today.
