Skip to content

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Getting Started",
      "link": "/started"
    },
    {
      "text": "Benchmarks",
      "link": "/benchmark"
    },
    {
      "text": "Examples",
      "link": "/examples"
    },
    {
      "text": "Community",
      "link": "/community"
    }
  ],
  "sidebar": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "Getting Started",
      "link": "/started"
    },
    {
      "text": "Attribution",
      "link": "/attribution"
    },
    {
      "text": "Feature Parity",
      "link": "/parity"
    },
    {
      "text": "Begin from zero",
      "items": [
        {
          "text": "Hello world",
          "link": "/hello-zero"
        },
        {
          "text": "Configs",
          "link": "/configuration"
        },
        {
          "text": "Logging",
          "link": "/logging"
        },
        {
          "text": "Observability",
          "link": "/observability"
        },
        {
          "text": "CLI Apps",
          "link": "/cli"
        },
        {
          "text": "Kubernetes",
          "link": "/kubernetes"
        },
        {
          "text": "Build and debug",
          "link": "/build-and-debug"
        }
      ]
    },
    {
      "text": "Built-in solutions",
      "items": [
        {
          "text": "Using SQL",
          "items": [
            {
              "text": "REST handler (Postgres)",
              "link": "/rest-handler"
            },
            {
              "text": "SQLite",
              "link": "/sqlite"
            },
            {
              "text": "DuckDB",
              "link": "/duckdb"
            }
          ]
        },
        {
          "text": "NoSQL & Analytics",
          "items": [
            {
              "text": "Cassandra",
              "link": "/cassandra"
            },
            {
              "text": "InfluxDB",
              "link": "/influxdb"
            },
            {
              "text": "Solr",
              "link": "/solr"
            }
          ]
        },
        {
          "text": "Using Redis",
          "link": "/caching"
        },
        {
          "text": "Migrations",
          "link": "/migrations"
        },
        {
          "text": "Schedule Tasks",
          "link": "/cronz"
        },
        {
          "text": "Using Pubsub",
          "items": [
            {
              "text": "PubSub",
              "link": "/pubsub"
            },
            {
              "text": "Kafka Publisher",
              "link": "/kafka-publisher"
            },
            {
              "text": "Kafka Subscriber",
              "link": "/kafka-subscriber"
            },
            {
              "text": "MQ Publisher",
              "link": "/message-queue-publisher"
            },
            {
              "text": "MQ Subscriber",
              "link": "/message-queue-subscriber"
            },
            {
              "text": "NATS Publisher",
              "link": "/nats-publisher"
            },
            {
              "text": "NATS Subscriber",
              "link": "/nats-subscriber"
            }
          ]
        },
        {
          "text": "Websockets",
          "link": "/websocket"
        },
        {
          "text": "Http Services",
          "link": "/http-service"
        },
        {
          "text": "Authentication",
          "link": "/authentication"
        },
        {
          "text": "HTMX CRUD",
          "link": "/htmx-crud"
        },
        {
          "text": "Warmup hooks",
          "link": "/warmup"
        },
        {
          "text": "Swagger Rendering",
          "link": "/swagger"
        },
        {
          "text": "GraphQL",
          "link": "/graphql"
        },
        {
          "text": "Protobuf",
          "link": "/protobuf"
        },
        {
          "text": "KV Store",
          "link": "/kv-store"
        },
        {
          "text": "File Store",
          "link": "/file-store"
        },
        {
          "text": "Auto CRUD",
          "link": "/auto-crud"
        },
        {
          "text": "Rate Limiter",
          "link": "/rate-limiter"
        }
      ]
    },
    {
      "text": "In-depth",
      "items": [
        {
          "text": "Architecture",
          "link": "/architecture"
        },
        {
          "text": "Container",
          "link": "/container"
        },
        {
          "text": "Context",
          "link": "/context"
        },
        {
          "text": "Interface",
          "link": "/interface"
        },
        {
          "text": "Testing",
          "link": "/testing"
        },
        {
          "text": "Benchmark",
          "link": "/benchmark"
        },
        {
          "text": "Resilience",
          "link": "/resilience"
        },
        {
          "text": "Roadmap",
          "link": "/timeline"
        },
        {
          "text": "X-Ray",
          "link": "/x-ray"
        },
        {
          "text": "Migrating to 0.16",
          "link": "/migrating-0-16"
        }
      ]
    }
  ],
  "appearance": "force-light",
  "title": "   ",
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/im-ng/zero"
    }
  ]
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.