> ## Documentation Index
> Fetch the complete documentation index at: https://docs.easelms.org/llms.txt
> Use this file to discover all available pages before exploring further.

# API Overview

> Learn about the EaseLMS API, including base URL, versioning, response formats, and common patterns

## 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:

```bash theme={null}
Content-Type: application/json
```

## Response Format

### Success Responses

Successful responses return a `200` status code with a JSON object:

```json theme={null}
{
  "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:

```json theme={null}
{
  "error": "Unauthorized"
}
```

### Common HTTP Status Codes

| Status Code | Meaning                                       |
| ----------- | --------------------------------------------- |
| `200`       | OK - Request succeeded                        |
| `201`       | Created - Resource successfully created       |
| `400`       | Bad Request - Invalid parameters              |
| `401`       | Unauthorized - Authentication required        |
| `403`       | Forbidden - Insufficient permissions          |
| `404`       | Not Found - Resource doesn't exist            |
| `409`       | Conflict - Resource already exists            |
| `500`       | Internal 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:

```bash theme={null}
GET /api/courses?recommended=true
```

### Filtering by IDs

Multiple resources can be retrieved by ID using comma-separated values:

```bash theme={null}
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:

<ParamField path="NEXT_PUBLIC_SUPABASE_URL" type="string" required>
  Your Supabase project URL
</ParamField>

<ParamField path="NEXT_PUBLIC_SUPABASE_ANON_KEY" type="string" required>
  Your Supabase anonymous/public API key
</ParamField>

<ParamField path="SUPABASE_SERVICE_ROLE_KEY" type="string" required>
  Your Supabase service role key for bypassing Row Level Security (RLS)
</ParamField>

<ParamField path="NEXT_PUBLIC_WEBSITE_URL" type="string">
  Your website URL for CORS configuration (optional, defaults to `*` in development)
</ParamField>

<ParamField path="NEXT_PUBLIC_APP_URL" type="string">
  Your application URL for internal API calls (optional, defaults to `http://localhost:3000`)
</ParamField>

## Next Steps

<CardGroup cols={2}>
  <Card title="Authentication" icon="lock" href="/api/authentication">
    Learn how to authenticate API requests
  </Card>

  <Card title="Courses API" icon="book" href="/api/courses">
    Work with courses and lessons
  </Card>

  <Card title="Users API" icon="users" href="/api/users">
    Manage users and profiles
  </Card>

  <Card title="Enrollments API" icon="user-plus" href="/api/enrollments">
    Handle course enrollments
  </Card>
</CardGroup>
