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": "Blog",
      "link": "/blog/"
    }
  ],
  "outline": "deep",
  "sidebar": {
    "/guides/": [
      {
        "text": "Examples",
        "items": [
          {
            "text": "Markdown Examples",
            "link": "/guides/markdown-examples"
          },
          {
            "text": "Runtime API Examples",
            "link": "/guides/api-examples"
          }
        ]
      },
      {
        "text": "HTTP Clients",
        "items": [
          {
            "text": "What is HTTP?",
            "link": "/guides/markdown-examples"
          },
          {
            "text": "HTTP clients in Spring",
            "items": [
              {
                "text": "RestTemplate",
                "link": "/guides/markdown-examples"
              },
              {
                "text": "WebClient",
                "link": "/guides/api-examples"
              },
              {
                "text": "RestClient",
                "link": "/guides/api-examples"
              },
              {
                "text": "OpenFeign",
                "link": "/guides/api-examples"
              }
            ]
          },
          {
            "text": "Declarative HTTP clients",
            "link": "/guides/api-examples"
          }
        ]
      }
    ],
    "/guides/spring-data-jpa/": [
      {
        "text": "Spring Data JPA",
        "items": [
          {
            "text": "Projections",
            "items": [
              {
                "text": "Introduction",
                "link": "/guides/spring-data-jpa/projections/introduction"
              },
              {
                "text": "JPA Projections",
                "link": "/guides/spring-data-jpa/projections/jpa-projections"
              },
              {
                "text": "Native SQL Projections",
                "link": "/guides/spring-data-jpa/projections/native-sql-projections"
              },
              {
                "text": "Entity Views",
                "link": "/guides/spring-data-jpa/projections/entity-views"
              }
            ]
          }
        ]
      }
    ]
  },
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/maciejwalkowiak"
    },
    {
      "icon": "twitter",
      "link": "https://twitter.com/maciejwalkowiak"
    },
    {
      "icon": "youtube",
      "link": "https://youtube.com/springacademy"
    },
    {
      "icon": {
        "svg": "<svg version=\"1.1\" id=\"Capa_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 455.731 455.731\" xml:space=\"preserve\"><g><rect x=\"0\" y=\"0\" style=\"fill:#F78422;\" width=\"455.731\" height=\"455.731\"/><g><path style=\"fill:#FFFFFF;\" d=\"M296.208,159.16C234.445,97.397,152.266,63.382,64.81,63.382v64.348 c70.268,0,136.288,27.321,185.898,76.931c49.609,49.61,76.931,115.63,76.931,185.898h64.348 C391.986,303.103,357.971,220.923,296.208,159.16z\"/><path style=\"fill:#FFFFFF;\" d=\"M64.143,172.273v64.348c84.881,0,153.938,69.056,153.938,153.939h64.348 C282.429,270.196,184.507,172.273,64.143,172.273z\"/><circle style=\"fill:#FFFFFF;\" cx=\"109.833\" cy=\"346.26\" r=\"46.088\"/></g></g></svg>"
      },
      "link": "/rss.xml",
      "ariaLabel": "RSS"
    }
  ]
}

Page Data

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

Page Frontmatter

{
  "outline": "deep"
}

More

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

Let's stay in touch and follow me on Twitter: @maciejwalkowiak

Subscribe to RSS feed