# Source: https://lynxjs.org/help/api.md

# Documenting APIs

The Lynx documentation relies on a structured system to ensure API references are accurate and consistent.

## Compatibility Data (`lynx-compat-data`)

The source of truth for platform compatibility is stored in `packages/lynx-compat-data`. This is a JSON database similar to MDN's browser-compat-data.

### Adding a New API

1. Navigate to `packages/lynx-compat-data`.
2. Find the appropriate JSON file (e.g., `lynx-api/global/console/log.json`).
3. Add your API definition following the schema.

## Displaying API Tables

To display a compatibility table in your documentation, use the `<APITable>` component.

### Using Frontmatter (Recommended)

It is recommended to define the `api` field in the frontmatter.

```yaml
---
api: lynx-api/global/console/log
---
```

Then place `<APITable />` in your MDX file. It will automatically read the `api` field.

```tsx
<APITable />
```

### Multiple Tables (Explicit Query)

When you need to display multiple tables on a single page, you can pass the `query` prop explicitly.

For example, in [fetch](/api/lynx-api/global/fetch.md), separate tables are used for `Headers`, `Request`, and `Response`:

```tsx
### Headers

<APITable query="lynx-api/fetch/Headers" />

### Request

<APITable query="lynx-api/fetch/Request" />
```

**Compatibility Table**
**Query:** `lynx-api.fetch.Headers`

**MDN Reference:** [https://developer.mozilla.org/docs/Web/API/Headers](https://developer.mozilla.org/docs/Web/API/Headers)

**Platform Support**

| Platform | Version Added | Notes |
|----------|---------------|-------|
| Android | 2.18 | - |
| iOS | 2.18 | - |
| HarmonyOS | 3.5 | - |
| Web | ✅ Yes | - |


You can verify valid queries using the [Interactive Explorer](#interactive-explorer) below.

## API Summary

For a high-level view of API groups (like methods, properties, events), use `<APISummary>`. Similar to `<APITable>`, it defaults to reading from the `api` frontmatter field.

```tsx
<APISummary />
```

## Interactive Explorer

You can use the explorer below to find valid API queries and preview their tables.

<APITableExplorer />

## Validating Documentation

We provide a script to ensure your API documentation matches the compatibility data.

```bash
pnpm run check-docs
```

This script (`scripts/check_api_doc`) checks for:

- Invalid `api` frontmatter keys.
- Missing documentation for defined APIs.

## TypeDoc Generation

API reference pages are automatically generated from TypeScript source code using TypeDoc.

- **Config**: `scripts/typedoc/`
- **Command**: `pnpm run typedoc`

Do not manually edit files generated by TypeDoc (usually in `docs/en/api/...`), as they will be overwritten. Edit the source comments instead.