Create complete RESTful APIs with best practices.
CanxJS excels at building high-performance APIs. Here are best practices.
Use API Resources to transform data before sending it to the client:
import { JsonResource } from "canxjs";
export class UserResource extends JsonResource {
toArray() {
return {
id: this.id,
name: this.name,
email: this.email,
// Hide created_at, updated_at, etc.
};
}
}Maintain a consistent response structure:
{
"data": { ... },
"meta": {
"page": 1,
"total": 50
}
}Always version your APIs using Route Groups:
app.group("/api/v1", (v1) => { /* ... */ });
app.group("/api/v2", (v2) => { /* ... */ });Have questions?
Join the discussion on GitHub