C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

Back to Learning Center
Intermediate
40 min

Building REST APIs

Create complete RESTful APIs with best practices.

Building REST APIs

CanxJS excels at building high-performance APIs. Here are best practices.

Consistency with API Resources

Use API Resources to transform data before sending it to the client:

typescript
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.
    };
  }
}

Standard Response Format

Maintain a consistent response structure:

json
{
  "data": { ... },
  "meta": {
    "page": 1,
    "total": 50
  }
}

Versioning

Always version your APIs using Route Groups:

typescript
app.group("/api/v1", (v1) => { /* ... */ });
app.group("/api/v2", (v2) => { /* ... */ });

Have questions?

Join the discussion on GitHub