Home / One YAML file, three outputs: API docs, web, and mobile

One YAML file, three outputs: API docs, web, and mobile

Olivier Carrère 4 min read
View as Markdown
On this page

Core premise: A single structured YAML file in Git powers a live REST endpoint, interactive Swagger documentation, static SEO-optimized HTML components, and mobile app payloads—eliminating manual content synchronization across channels.

  1. 1. YAML source of truth
  2. 2. Astro API & build pipeline
  3. 3. Interactive Swagger docs
  4. 4. Prerendered HTML tables
  5. 5. Mobile & client apps

This article demonstrates how to build a self-documenting API in Astro using a single source of truth. You can inspect the live implementation right now in the interactive API documentation.

To understand why this architecture matters, consider three immediate questions:

  • What is being demonstrated? An Astro site hosting both its human-facing documentation and its machine-readable REST endpoints from the same codebase.
  • What is the source of truth? A plain-text YAML file (oil-types.yaml) stored directly in Git.
  • What are the three outputs? Interactive Swagger/OpenAPI documentation, prerendered static HTML tables, and live JSON payloads consumed by web or mobile applications.
Displaying the same information on a mobile app and on a web page from a single YAML source.
One source, multiple form factors: mobile application cards and desktop web pages rendered from the same reference data.

One YAML file, many outputs

By storing structured reference information in a single YAML file, you establish a unified distribution workflow. The data flows seamlessly into interactive API documentation, SEO-friendly HTML pages, or direct REST API responses.

This approach builds directly on the catalog architecture explored in What YAML gives technical docs that XML and Markdown can’t. In that article, we examined how YAML eliminates table maintenance headaches; here, we extend that exact same dataset into a headless delivery engine.

1. Source Layer

YAML plain file in Git

oil-types.yaml stores catalog facts once. Technical writers and domain experts edit data using standard Git branch-and-PR workflows.

2. Transformation

Astro build & API routes

TypeScript API endpoints (/api/oil-types) and static component templates import the YAML file directly, handling serialization and typing.

3. Output Channels

Multi-medium delivery

Interactive Swagger UI for developers, prerendered HTML tables for search engines, and live JSON payloads for client applications.

Displaying the same information on a mobile app and on a web page from the same source.
Multi-channel distribution: publishing static documentation alongside live machine-readable endpoints.

The diagram below maps how the YAML source powers every channel without content duplication or synchronization scripts:

YAML Multi-Output API Architecture Diagram

YAML Source File
oil-types.yaml

OpenAPI Schema
/api/oil-types/schema

Astro Build Engine
Static prerendering

REST API Route
/api/oil-types

Interactive Swagger UI
/docs

Prerendered HTML
SEO tables & lists

JSON Response
fetch / curl

Client Applications
Mobile & web apps

Figure 1 — Multi-output publishing architecture: single YAML dataset driving responsive web pages and machine-readable API endpoints.

Querying the API in practice

The live endpoint can be queried directly from client-side JavaScript or from your terminal.

  1. 1. Client sends request (fetch / curl)
  2. 2. Astro endpoint imports YAML
  3. 3. Payload serialized to JSON (200 OK)
  4. 4. Client renders structured response

Client-side integration: JavaScript fetch

For web components, mobile web views, or single-page applications, query the endpoint using modern fetch:

JavaScript fetch example JS
// Fetch all oil types from the live Astro endpoint
fetch("https://redaction-technique.org/api/oil-types")
  .then((res) => res.json())
  .then((data) => {
    console.log("Oil catalog data:", data);
  });

Terminal testing: cURL

For command-line testing, shell automation, or continuous integration checks, inspect the endpoint with curl:

Terminal cURL example cURL
# Query the live endpoint from terminal
curl https://redaction-technique.org/api/oil-types

Inspecting the structured JSON response

Calling GET /api/oil-types returns the full structured catalog serialized directly from the source YAML:

Endpoint: GET /api/oil-types  |  Status: 200 OK  |  Content-Type: application/json

{
  "id": "oil-types",
  "title": "Oil types",
  "shortdesc": "You will find below the recommended oil types.",
  "properties": {
    "headers": {
      "type": "Type",
      "value": "Brand",
      "description": "Use"
    },
    "rows": [
      {
        "type": "Primary oil",
        "value": "A1X",
        "description": "One-cylinder engines"
      },
      {
        "type": "Secondary oil",
        "value": "B2Z",
        "description": "Two-cylinder engines"
      }
    ]
  }
}

Notice: The JSON response retains the top-level document metadata (id, title, shortdesc) alongside the structured tabular rows (headers, rows). The API does not flatten or obscure the data model—it exposes the exact semantic structure defined in oil-types.yaml.


Why YAML as the source of truth?

Instead of maintaining a static JSON schema and manually duplicating it into documentation topics, the entire specification generates directly from YAML.

  1. 1. Update fact in oil-types.yaml
  2. 2. Peer review via Git pull request
  3. 3. CI/CD build triggered on merge
  4. 4. API endpoint updates response
  5. 5. Prerendered HTML tables refresh

This architecture delivers three decisive operational advantages:

  1. Zero drift across channels: The API endpoint, the interactive Swagger UI, and the documentation pages cannot diverge because there is only one file to edit.
  2. Automated multi-channel propagation: When an engineer or technical writer updates a product name, price, or viscosity grade in oil-types.yaml, every downstream consumer refreshes during the next build.
  3. Auditability and docs-as-code: Storing reference data in plain files rather than a database keeps your content version-controlled, easily diffable, and reviewable using pull requests.

Build-time vs. runtime synergy: The exact same YAML file serves dual duty in Astro. At build time, Astro components import oil-types.yaml to prerender fast, SEO-friendly HTML tables. At runtime, the API route exposes it as dynamic JSON for external consumers—all without writing synchronization scripts.


As explained in Strong Information Typing Without XML Overhead, modern docs-as-code workflows let technical writers structure information using lightweight, open tools without the operational complexity of legacy XML pipelines.

External sources

Hero image: “Mitchell River delta” by Feral Arts, licensed under CC BY 2.0.

Follow Olivier Carrère on LinkedIn

Continuous writing on docs-as-code, DITA XML, YAML, and AI-assisted documentation pipelines.

Follow ↗