πŸ“š Dictionary API Documentation

← Back to Home

Introduction

Welcome to the English-Khmer Dictionary API documentation. This RESTful API provides access to dictionary data with authentication, rate limiting, and subscription management.

Base URL:
πŸ” Authentication Required: Most endpoints require authentication. Include your JWT token in the Authorization header: Authorization: Bearer YOUR_TOKEN
POST /api/auth/signup

Register a new user account.

Request Body

Parameter Type Description
email Required string User email address
password Required string User password
name Required string User's full name

Example Request

POST /api/auth/signup
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "SecurePass123!",
  "name": "John Doe"
}

Error Response (400 Bad Request)

{
  "error": "User already exists"
}

Response (201 Created)

{
  "message": "User created successfully",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "email": "user@example.com",
    "name": "John Doe"
  }
}
POST /api/auth/login

Authenticate and receive a JWT token.

Request Body

Parameter Type Description
email Required string User email address
password Required string User password

Example Request

POST /api/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "SecurePass123!"
}

Response (200 OK)

{
  "message": "Login successful",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImV4cCI6MTcxNDc2ODAwMH0.abc123...",
  "user": {
    "id": 1,
    "email": "user@example.com",
    "name": "John Doe"
  }
}

Error Response (401 Unauthorized)

{
  "error": "Invalid credentials"
}
GET /api/auth/me

Get current authenticated user information.

πŸ” Requires Authentication

Example Request

GET /api/auth/me
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Response (200 OK)

{
  "user": {
    "id": 1,
    "email": "user@example.com",
    "name": "John Doe"
  }
}

Error Response (401 Unauthorized)

{
  "error": "Invalid or expired token"
}
GET /api/dictionary/search

Search for words in the dictionary. Supports partial matching and pagination.

πŸ” Requires Authentication | ⏱️ Rate Limited

Note: You can also use /api/dictionary without the /search path.

Query Parameters

Parameter Type Default Description
query Optional string - Search query (partial match, case-insensitive). If omitted, returns all words with pagination.
limit Optional integer 100 Maximum number of results to return (1-1000)
offset Optional integer 0 Number of results to skip for pagination

Example Requests

Search for words containing "hello"

GET /api/dictionary/search?query=hello&limit=10
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Alternative: GET /api/dictionary?query=hello&limit=10

Get all words with pagination

GET /api/dictionary/search?limit=50&offset=0
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Alternative: GET /api/dictionary?limit=50&offset=0

Search with pagination (next page)

GET /api/dictionary/search?query=book&limit=20&offset=20
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Alternative: GET /api/dictionary?query=book&limit=20&offset=20

Response (200 OK)

{
  "words": [
    {
      "id": 123,
      "englishWord": "hello",
      "partOfSpeech": "noun",
      "englishPhonetic": "hΙ™Λˆloʊ",
      "khmerPhonetic": "αžŸαž½αžŸαŸ’αžαžΈ",
      "khmerDef": "<ul><li><span style=\"color: #0000ff\">greeting</span></li></ul>"
    },
    {
      "id": 124,
      "englishWord": "hello there",
      "partOfSpeech": "phrase",
      "englishPhonetic": "hΙ™Λˆloʊ Γ°Ι›r",
      "khmerPhonetic": "αžŸαž½αžŸαŸ’αžαžΈαž“αŸ…αž‘αžΈαž“αŸ„αŸ‡",
      "khmerDef": "<ul><li>A friendly greeting</li></ul>"
    }
  ],
  "count": 2
}

Response Fields

Field Type Description
words array Array of word objects matching the search
words[].id integer Unique word identifier
words[].englishWord string The English word
words[].partOfSpeech string Part of speech (noun, verb, adjective, etc.)
words[].englishPhonetic string English phonetic pronunciation
words[].khmerPhonetic string Khmer phonetic pronunciation
words[].khmerDef string Khmer definition (HTML formatted)
count integer Number of words returned in this response
GET /api/dictionary/word

Get a specific word by ID or exact match. Returns a single word object.

πŸ” Requires Authentication | ⏱️ Rate Limited

Query Parameters

Parameter Type Description
id Optional integer Word ID (e.g., 123). Either id or word must be provided.
word Optional string Exact word match (case-insensitive, e.g., "hello")

Note: You must provide either id or word parameter.

Example Requests

Get word by ID

GET /api/dictionary/word?id=123
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Alternative: GET /api/dictionary?id=123

Get word by exact match

GET /api/dictionary/word?word=hello
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Alternative: GET /api/dictionary?word=hello

Response (200 OK)

{
  "id": 123,
  "englishWord": "hello",
  "partOfSpeech": "noun",
  "englishPhonetic": "hΙ™Λˆloʊ",
  "khmerPhonetic": "αžŸαž½αžŸαŸ’αžαžΈ",
  "khmerDef": "<ul><li><span style=\"color: #0000ff\">greeting</span></li></ul>"
}

Error Response (404 Not Found)

{
  "error": "Word not found"
}
GET /api/subscription/plans

Get all available subscription plans with their rate limits and pricing.

Note: This endpoint does not require authentication.

Example Request

GET /api/subscription/plans

Response (200 OK)

{
  "plans": [
    {
      "id": "free",
      "name": "Free",
      "rateLimit": 10,
      "price": 0
    },
    {
      "id": "basic",
      "name": "Basic",
      "rateLimit": 50,
      "price": 9.99
    },
    {
      "id": "premium",
      "name": "Premium",
      "rateLimit": 200,
      "price": 19.99
    },
    {
      "id": "enterprise",
      "name": "Enterprise",
      "rateLimit": 1000,
      "price": 49.99
    }
  ]
}
GET /api/subscription/current

Get the current user's active subscription and rate limit information.

πŸ” Requires Authentication

Example Request

GET /api/subscription/current
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Response (200 OK)

{
  "subscription": {
    "id": 5,
    "user_id": 1,
    "plan_name": "Premium",
    "rate_limit": 200,
    "status": "active",
    "created_at": "2024-01-01 00:00:00",
    "expires_at": "2024-02-01 00:00:00"
  },
  "currentRateLimit": 200,
  "plan": "premium"
}

Response (200 OK) - No Active Subscription

{
  "subscription": null,
  "currentRateLimit": 10,
  "plan": "free"
}
GET /api/subscription/rate-limit

Get current rate limit status including remaining requests and reset time.

πŸ” Requires Authentication

Example Request

GET /api/subscription/rate-limit
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Response (200 OK)

{
  "rateLimit": 200,
  "currentCount": 45,
  "resetAt": "2024-01-01T00:01:00+00:00",
  "remaining": 155
}
POST /api/subscription/subscribe

Subscribe to a plan.

πŸ” Requires Authentication

Request Body

Parameter Type Description
planId Required string Plan ID: free, basic, premium, or enterprise

Example Request

POST /api/subscription/subscribe
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json

{
  "planId": "premium"
}

Response (200 OK)

{
  "message": "Subscription successful",
  "subscription": {
    "id": 5,
    "planName": "Premium",
    "rateLimit": 200,
    "expiresAt": "2024-02-01T00:00:00+00:00"
  }
}

Error Response (400 Bad Request)

{
  "error": "Invalid plan ID"
}
GET /api/health

Check API health status.

Response (200 OK)

{
  "status": "ok",
  "dictionary": "connected",
  "timestamp": "2024-01-01T00:00:00+00:00"
}
Error Error Responses

401 Unauthorized

{
  "error": "Authentication required"
}

429 Too Many Requests

{
  "error": "Rate limit exceeded",
  "message": "You have exceeded your rate limit...",
  "rateLimit": 10,
  "resetAt": "2024-01-01T00:01:00+00:00"
}

500 Internal Server Error

{
  "error": "Internal server error"
}