|
| 1 | +# API Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Forward Email provides a comprehensive API for managing email forwarding, domains, aliases, and more. The API documentation is generated from an OpenAPI specification and rendered using [Scalar](https://github.com/scalar/scalar). |
| 6 | + |
| 7 | +## API Specification Process |
| 8 | + |
| 9 | +The API specification is maintained as a structured OpenAPI v3 JSON file: |
| 10 | + |
| 11 | +- **File Location**: The specification is stored as `api-spec.json` in the `assets/` folder |
| 12 | +- **Build Process**: During the build process, the specification is copied to the build folder |
| 13 | +- **Web Routes**: The API documentation is served via the `/api` and `/email-api` web routes |
| 14 | +- **Renderer**: The documentation is rendered using Scalar API tool, configured in `app/views/email-api.pug` |
| 15 | + |
| 16 | +## Maintaining the API Specification |
| 17 | + |
| 18 | +When updating the API, follow these steps to maintain the specification: |
| 19 | + |
| 20 | +1. **Edit the Specification**: Update `assets/api-spec.json` with new endpoints, schemas, or descriptions |
| 21 | +2. **Use Markdown**: Leverage rich markdown in descriptions for better rendering in Scalar |
| 22 | +3. **Follow Best Practices**: |
| 23 | + - Keep the main API description concise and high-level |
| 24 | + - Place error details in the Error schema component |
| 25 | + - Add specific examples to individual endpoints |
| 26 | + - Use tables for parameter descriptions |
| 27 | + - Include code examples with syntax highlighting |
| 28 | + |
| 29 | +## Markdown Enhancement Guidelines |
| 30 | + |
| 31 | +The API specification uses markdown for rich documentation in Scalar: |
| 32 | + |
| 33 | +### Schema Descriptions |
| 34 | + |
| 35 | +```json |
| 36 | +{ |
| 37 | + "schemas": { |
| 38 | + "Example": { |
| 39 | + "description": "## Example Object\n\n### Properties Overview\n\n| Property | Type | Description |\n|----------|------|-------------|\n| id | string | Unique identifier |\n| name | string | The name of the example |\n\n### Example JSON\n\n```json\n{\n \"id\": \"123\",\n \"name\": \"Example Name\"\n}\n```" |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### Endpoint Descriptions |
| 46 | + |
| 47 | +```json |
| 48 | +{ |
| 49 | + "paths": { |
| 50 | + "/v1/example": { |
| 51 | + "get": { |
| 52 | + "description": "**Get Example**\n\n### Parameters\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| id | string | Yes | Example ID |\n\n### Example Request\n\n```bash\ncurl https://api.forwardemail.net/v1/example \\\n -u API_TOKEN:\n```\n\n### Example Response\n\n```json\n{\n \"id\": \"123\",\n \"name\": \"Example Name\"\n}\n```" |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +## Testing Documentation Changes |
| 60 | + |
| 61 | +After updating the API specification: |
| 62 | + |
| 63 | +1. Run the build process to copy the updated specification to the build folder |
| 64 | +2. Navigate to `/api` or `/email-api` in your development environment |
| 65 | +3. Verify that the documentation renders correctly in Scalar |
| 66 | +4. Check that all markdown formatting appears as expected |
| 67 | +5. Test the "Try It" functionality if available |
| 68 | + |
| 69 | +## Scalar Configuration |
| 70 | + |
| 71 | +The Scalar API documentation tool is configured in `app/views/email-api.pug`. If you need to customize the Scalar rendering: |
| 72 | + |
| 73 | +1. Edit the configuration in this file |
| 74 | +2. Refer to the [Scalar documentation](https://github.com/scalar/scalar) for available options |
| 75 | +3. Test changes in the development environment before deploying |
| 76 | + |
| 77 | +## Deployment |
| 78 | + |
| 79 | +When deploying API documentation changes: |
| 80 | + |
| 81 | +1. Ensure the updated `api-spec.json` is included in the deployment |
| 82 | +2. Verify that the build process correctly copies the specification |
| 83 | +3. Check the live documentation after deployment to confirm changes are visible |
0 commit comments