Get a page

Updated on

Overview

Stubby provides you simple api's to fetch data into your next app. You can simply send a get request to the this url

TypeValue
methodGET
urlhttps://stubby.io/api/v1/sites/{siteId}/pages/{id | slug}

Parameters

PropertyValueComment
apiKeystringApi key from stubby.io

Sample code

const STUBBY_CMS_API_KEY = "<API_KEY>"; 
const siteId = "<YOUR_SITE_ID>";
const slugOrId = "hello-world";

const url = new URL(`https://stubby.io/api/v1/sites/${siteId}/pages/${slugOrId}`);
url.searchParams.append("apiKey", STUBBY_CMS_API_KEY);

const res = await fetch(url.href);

const data = await res.json(); // data contains the page content

Response

The response will be sent as a tree structure representing the folder structure you have organized in your app.

[
  {
  "id": string,
  "createdAt": string,
  "updatedAt": string,
  "parentId": string | null,
  "name": string,
  "slug": string,
  "title": string,
  "user": {
    "name": string,
    "image": string,
    "email": string
  },
  "content": string, 
  "metadata": {
    [key: string]: any
  }, 
  "toc": [
    {
      "name": string, 
      "id": string, 
      "level": "h1" | "h2" | "h3" | "h4" | "h5"
    }
  ]
 }
]