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

# Resources API

> Access documents, reports, and educational resources

## GET /api/resources

Retrieve a list of all resources, documents, and reports related to Dzaleka Refugee Camp.

### Query Parameters

This endpoint does not require any query parameters.

### Response Format

<ResponseField name="status" type="string" required>
  Status of the API response ("success" or "error")
</ResponseField>

<ResponseField name="count" type="number" required>
  Total number of resources returned
</ResponseField>

<ResponseField name="data" type="object" required>
  Container for the resources data

  <ResponseField name="resources" type="array" required>
    Array of resource objects

    <ResponseField name="id" type="string">
      Unique identifier for the resource
    </ResponseField>

    <ResponseField name="collection" type="string">
      Collection name ("resources")
    </ResponseField>

    <ResponseField name="title" type="string">
      Resource title
    </ResponseField>

    <ResponseField name="description" type="string">
      Resource description
    </ResponseField>

    <ResponseField name="date" type="string">
      Publication or creation date (YYYY-MM-DD)
    </ResponseField>

    <ResponseField name="category" type="string">
      Resource category (e.g., "Situation Reports / Updates", "Guidelines", "Research")
    </ResponseField>

    <ResponseField name="fileType" type="string">
      File type (e.g., "pdf", "doc", "xlsx")
    </ResponseField>

    <ResponseField name="resourceUrl" type="string">
      URL to view the resource online
    </ResponseField>

    <ResponseField name="downloadUrl" type="string">
      Direct download URL
    </ResponseField>

    <ResponseField name="fileSize" type="string">
      File size (e.g., "748.24 KB", "2.5 MB")
    </ResponseField>

    <ResponseField name="lastUpdated" type="string">
      Last update date (YYYY-MM-DD)
    </ResponseField>

    <ResponseField name="languages" type="array">
      Array of available languages
    </ResponseField>

    <ResponseField name="featured" type="boolean">
      Whether the resource is featured
    </ResponseField>

    <ResponseField name="author" type="string">
      Author or publishing organization
    </ResponseField>
  </ResponseField>
</ResponseField>

### Error Responses

<ResponseField name="status" type="string">
  "error"
</ResponseField>

<ResponseField name="message" type="string">
  Error message description
</ResponseField>

<ResponseField name="error" type="string">
  Detailed error information
</ResponseField>

**Status Codes:**

* `200` - Success
* `429` - Rate limit exceeded (60 requests per minute)
* `500` - Internal server error

### Rate Limiting

All API endpoints are rate-limited to 60 requests per minute per IP address. Rate limit headers are included in responses:

* `X-RateLimit-Limit`: Maximum requests per window
* `X-RateLimit-Remaining`: Remaining requests in current window
* `X-RateLimit-Reset`: Timestamp when the rate limit resets
* `Retry-After`: Seconds to wait before retrying (only on 429 responses)

### Example Request

```bash theme={null}
curl -X GET "https://services.dzaleka.com/api/resources" \
  -H "Content-Type: application/json"
```

### Example Response

```json theme={null}
{
  "status": "success",
  "count": 1,
  "data": {
    "resources": [
      {
        "id": "Banking-services-in-Dzaleka-Refugee-Camp",
        "collection": "resources",
        "title": "Banking services in Dzaleka Refugee Camp",
        "description": "New Finance Bank opened its branch of service in Dzaleka Refugee Camp on 12 April 2018.",
        "date": "2019-03-01",
        "category": "Situation Reports / Updates",
        "fileType": "pdf",
        "resourceUrl": "https://data.unhcr.org/en/documents/details/68623",
        "downloadUrl": "https://data.unhcr.org/en/documents/download/68623",
        "fileSize": "748.24 KB",
        "lastUpdated": "2024-12-27",
        "languages": ["English"],
        "featured": false,
        "author": "UNHCR Malawi"
      }
    ]
  }
}
```

## POST /api/resources

Retrieve resources data with optional metadata and statistics.

### Request Body

<ParamField body="options" type="object">
  Optional configuration for the response

  <ParamField body="includeMetadata" type="boolean">
    Include export metadata in response
  </ParamField>

  <ParamField body="includeStats" type="boolean">
    Include statistics in response
  </ParamField>
</ParamField>

### Response Format

Same as GET endpoint, with optional additional fields:

<ResponseField name="metadata" type="object">
  Export metadata (only if `includeMetadata: true`)

  <ResponseField name="exportDate" type="string">
    ISO 8601 timestamp of export
  </ResponseField>

  <ResponseField name="collection" type="string">
    Collection name
  </ResponseField>
</ResponseField>

<ResponseField name="stats" type="object">
  Statistics (only if `includeStats: true`)

  <ResponseField name="totalItems" type="number">
    Total number of items
  </ResponseField>

  <ResponseField name="collection" type="string">
    Collection name
  </ResponseField>
</ResponseField>

### Example Request

```bash theme={null}
curl -X POST "https://services.dzaleka.com/api/resources" \
  -H "Content-Type: application/json" \
  -d '{
    "options": {
      "includeMetadata": true,
      "includeStats": true
    }
  }'
```

### Example Response

```json theme={null}
{
  "status": "success",
  "count": 156,
  "data": {
    "resources": [
      {
        "id": "Banking-services-in-Dzaleka-Refugee-Camp",
        "title": "Banking services in Dzaleka Refugee Camp",
        "category": "Situation Reports / Updates",
        "fileType": "pdf",
        "author": "UNHCR Malawi"
      }
    ]
  },
  "metadata": {
    "exportDate": "2025-03-09T12:00:00.000Z",
    "collection": "resources"
  },
  "stats": {
    "totalItems": 156,
    "collection": "resources"
  }
}
```

## Implementation

The Resources API is implemented using the `createGetHandler` and `createPostHandler` utility functions from `src/utils/api-utils.ts:118`.

Source code: `src/pages/api/resources.ts:5`
