Skip to main content

API Styleguide

Panduan untuk design API yang konsisten dan RESTful.

🎯 REST Principles

HTTP Methods

  • GET: Retrieve data
  • POST: Create new resource
  • PUT: Update entire resource
  • PATCH: Partial update
  • DELETE: Remove resource

Status Codes

  • 200 OK: Success
  • 201 Created: Resource created
  • 400 Bad Request: Validation error
  • 401 Unauthorized: Authentication required
  • 403 Forbidden: Insufficient permissions
  • 404 Not Found: Resource not found
  • 500 Internal Server Error: Server error

📝 Response Format

Success Response

{
  "data": {
    "id": "123",
    "name": "Product"
  },
  "meta": {
    "page": 1,
    "total": 100
  }
}

Error Response

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input",
    "details": [
      {
        "field": "email",
        "message": "Invalid email format"
      }
    ],
    "traceId": "abc123"
  }
}

🔐 Authentication

Authorization: Bearer <jwt_token>