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": "/0.15.2/"
    },
    {
      "text": "Getting Started",
      "link": "/0.15.2/started"
    }
  ],
  "sidebar": [
    {
      "text": "Home",
      "link": "/0.15.2/"
    },
    {
      "text": "Getting Started",
      "link": "/0.15.2/started"
    },
    {
      "text": "Attribution",
      "link": "/0.15.2/attribution"
    },
    {
      "text": "Feature Parity",
      "link": "/0.15.2/parity"
    },
    {
      "text": "Begin from zero",
      "items": [
        {
          "text": "Hello world",
          "link": "/0.15.2/hello-zero"
        },
        {
          "text": "Configs",
          "link": "/0.15.2/configuration"
        },
        {
          "text": "Logging",
          "link": "/0.15.2/logging"
        },
        {
          "text": "Observability",
          "link": "/0.15.2/observability"
        },
        {
          "text": "PubSub",
          "link": "/0.15.2/pubsub"
        }
      ]
    },
    {
      "text": "Built-in solutions",
      "items": [
        {
          "text": "Using Postgres",
          "link": "/0.15.2/rest-handler"
        },
        {
          "text": "Using Redis",
          "link": "/0.15.2/caching"
        },
        {
          "text": "Migrations",
          "link": "/0.15.2/migrations"
        },
        {
          "text": "Schedule Tasks",
          "link": "/0.15.2/cronz"
        },
        {
          "text": "Kafka Publisher",
          "link": "/0.15.2/kafka-publisher"
        },
        {
          "text": "Kafka Subscriber",
          "link": "/0.15.2/kafka-subscriber"
        },
        {
          "text": "MQ Publisher",
          "link": "/0.15.2/message-queue-publisher"
        },
        {
          "text": "MQ Subscriber",
          "link": "/0.15.2/message-queue-subscriber"
        },
        {
          "text": "Websockets",
          "link": "/0.15.2/websocket"
        },
        {
          "text": "Http Services",
          "link": "/0.15.2/http-service"
        },
        {
          "text": "Authentication",
          "link": "/0.15.2/authentication"
        },
        {
          "text": "HTMX CRUD",
          "link": "/0.15.2/htmx-crud"
        },
        {
          "text": "Warmup hooks",
          "link": "/0.15.2/warmup"
        },
        {
          "text": "Swagger Rendering",
          "link": "/0.15.2/swagger"
        }
      ]
    },
    {
      "text": "In-depth",
      "items": [
        {
          "text": "Architecture",
          "link": "/0.15.2/architecture"
        },
        {
          "text": "Container",
          "link": "/0.15.2/container"
        },
        {
          "text": "Context",
          "link": "/0.15.2/context"
        },
        {
          "text": "Roadmap",
          "link": "/0.15.2/timeline"
        },
        {
          "text": "X-Ray",
          "link": "/0.15.2/x-ray"
        }
      ]
    }
  ],
  "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": "0.15.2/api-examples.md",
  "filePath": "0.15.2/api-examples.md"
}

Page Frontmatter

{
  "outline": "deep"
}

More

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