Skip to content

Response Format

Default format

All responses follow the same envelope:

Success

{
"data": { ... }
}

List responses include metadata:

{
"data": [{ "id": 1, "name": "John" }],
"meta": { "total": 42, "limit": 20, "offset": 0 }
}

Error

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Field \"password\" is not allowed in where",
"status": 422
}
}

Status codes

OperationSuccessNot FoundValidation Error
list200422
findById200404422
create201422
update200404422
remove200404422
count200422
aggregate200422

Error codes

CodeStatusWhen
VALIDATION_ERROR422Invalid where, orderBy, select, or body
NOT_FOUND404Record not found (findById, update, remove)
BAD_REQUEST400Malformed request
INTERNAL_ERROR500Unexpected server error

Envelope helpers

For custom endpoints, use the helper functions directly:

import { envelope, errorEnvelope } from '@relayerjs/next';
export async function GET(req: Request) {
const users = await r.users.findMany();
return envelope(undefined, users, { total: users.length });
}
export async function POST(req: Request) {
if (!isValid) {
return errorEnvelope(undefined, {
code: 'VALIDATION_ERROR',
message: 'Name is required',
status: 422,
});
}
}