Skip to main content

Introduction

The EaseLMS API is a RESTful API built with Next.js API routes that provides programmatic access to your learning management system. All API endpoints return JSON responses and use standard HTTP response codes.

Base URL

All API requests should be made to:
https://your-domain.com/api
For local development:
http://localhost:3000/api

Versioning

The current API does not use versioning in the URL path. All endpoints are accessed directly under /api/ route.

Request Format

HTTP Methods

The API uses standard HTTP methods:
  • GET - Retrieve resources
  • POST - Create new resources
  • PATCH - Update existing resources
  • PUT - Replace existing resources
  • DELETE - Remove resources

Content Type

All requests with a body should use application/json content type:
Content-Type: application/json

Response Format

Success Responses

Successful responses return a 200 status code with a JSON object:
{
  "courses": [
    {
      "id": 1,
      "title": "Introduction to Programming",
      "description": "Learn the basics of programming",
      "is_published": true,
      "price": 49.99,
      "enrolledStudents": 150
    }
  ]
}

Error Responses

Error responses include an error message and appropriate HTTP status code:
{
  "error": "Unauthorized"
}

Common HTTP Status Codes

Status CodeMeaning
200OK - Request succeeded
201Created - Resource successfully created
400Bad Request - Invalid parameters
401Unauthorized - Authentication required
403Forbidden - Insufficient permissions
404Not Found - Resource doesn’t exist
409Conflict - Resource already exists
500Internal Server Error - Server error occurred

CORS

The API supports Cross-Origin Resource Sharing (CORS) for API routes. CORS headers are automatically added:
  • Allowed Origin: Configured via NEXT_PUBLIC_WEBSITE_URL environment variable (or * for development)
  • Allowed Methods: GET, POST, PUT, DELETE, OPTIONS
  • Allowed Headers: Content-Type, Authorization
  • Max Age: 86400 seconds (24 hours)

Rate Limiting

Currently, the API does not implement rate limiting. This may be added in future versions.

Common Patterns

Pagination

Most list endpoints support query parameters for filtering:
GET /api/courses?recommended=true

Filtering by IDs

Multiple resources can be retrieved by ID using comma-separated values:
GET /api/courses?ids=1,2,3

Service Role Access

Public endpoints (like course listings) can be accessed without authentication. Protected endpoints require valid authentication tokens.

Environment Variables

The API requires the following environment variables:
NEXT_PUBLIC_SUPABASE_URL
string
required
Your Supabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY
string
required
Your Supabase anonymous/public API key
SUPABASE_SERVICE_ROLE_KEY
string
required
Your Supabase service role key for bypassing Row Level Security (RLS)
NEXT_PUBLIC_WEBSITE_URL
string
Your website URL for CORS configuration (optional, defaults to * in development)
NEXT_PUBLIC_APP_URL
string
Your application URL for internal API calls (optional, defaults to http://localhost:3000)

Next Steps