Skip to content
68 changes: 68 additions & 0 deletions api/docs-json-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Docs JSON API (Experimental)
summary: Provide a structured JSON API for TiDB docs with topic and feature filters.
---

# Docs JSON API (Experimental)

This API layer exposes structured metadata for markdown docs.

## Why

- Query docs by feature token (for example, `tidb_max_dist_task_nodes`)
- Query docs by topic/category
- Return structured schema instead of raw markdown only

## Data schema

Each doc record includes:

- `id`
- `path`
- `title`
- `summary`
- `product`
- `topics`
- `features`
- `headings`
- `frontMatter`
- `frontMatterRaw`
- `updatedAt`

## Build index

```bash
npm run docs-api:build
```

Default output file: `tmp/docs-api-index.json`

## Run API server

```bash
npm run docs-api:serve
```

Default host and port: `127.0.0.1:3000`

## Endpoints

- `GET /healthz`
- `GET /schema`
- `GET /topics`
- `GET /features`
- `GET /features?prefix=tidb_`
- `GET /docs`
- `GET /docs?feature=tidb_max_dist_task_nodes`
- `GET /docs?topic=tidb-cloud`
- `GET /docs?q=resource control`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The query parameter q=resource control contains an unencoded space. In a URL, spaces should be encoded as %20 or + to be technically accurate.

Suggested change
- `GET /docs?q=resource control`
- `GET /docs?q=resource%20control`
References
  1. Ensure technical accuracy in documentation, such as proper URL encoding. (link)

- `GET /docs?feature=tidb_max_dist_task_nodes&limit=10&offset=0`
- `GET /reload` (reload in-memory index)

## Environment variables

- `DOCS_API_HOST` (default `127.0.0.1`)
- `DOCS_API_PORT` (default `3000`)
- `DOCS_API_ROOT` (default current working directory)
- `DOCS_API_INDEX_FILE` (optional prebuilt JSON index path)

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"main": "index.js",
"license": "MIT",
"type": "module",
"scripts": {
"docs-api:build": "node scripts/build-docs-api-index.js",
"docs-api:serve": "node scripts/docs-api-server.js"
},
"dependencies": {
"axios": "^1.4.0",
"glob": "^8.0.3",
Expand Down
22 changes: 22 additions & 0 deletions scripts/build-docs-api-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as fs from "fs";
import path from "path";
import { buildDocsIndex } from "./docs-api-lib.js";

const args = process.argv.slice(2);
const outputArg = args[0] || "tmp/docs-api-index.json";
const rootArg = args[1] || process.cwd();

const outputPath = path.resolve(outputArg);
const outputDir = path.dirname(outputPath);

if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

const index = buildDocsIndex(rootArg);
fs.writeFileSync(outputPath, JSON.stringify(index, null, 2), "utf8");

console.log(
`Docs API index generated: ${outputPath} (${index.totalDocs} docs, ${index.features.length} features)`
);

Loading
Loading