tca-api-headless

This page is a TYPO3 page.

Every sentence here was written in a TYPO3 page tree and delivered as JSON by tca-api-headless: composed pages, typed content elements, navigation and SEO meta for any frontend. Each proof shows the request, the JSON and the TypeScript type behind a section.

composer require maikschneider/tca-api-headless:dev-main \
  "maikschneider/tca-api:dev-main as 2.4.0"
Proofregions.hero[1], regions.hero[2]

Request GET /website/_api/headless_pages/2000 regions.hero[1], regions.hero[2] Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

[
  {
    "uid": 2004,
    "CType": "header",
    "header": "Start in five steps",
    "header_layout": 0,
    "header_position": "",
    "header_link": {
      "href": "https://typo3.example/website/quick-start",
      "target": null,
      "title": "Quick start"
    },
    "subheader": "",
    "layout": 0,
    "frame_class": "default",
    "space_before_class": "",
    "space_after_class": ""
  },
  {
    "uid": 2005,
    "CType": "header",
    "header": "Source on GitHub",
    "header_layout": 0,
    "header_position": "",
    "header_link": {
      "href": "https://github.com/maikschneider/tca-api-headless",
      "target": "_blank",
      "title": "tca-api-headless on GitHub"
    },
    "subheader": "",
    "layout": 0,
    "frame_class": "default",
    "space_before_class": "",
    "space_after_class": ""
  }
]

Generated TypeScript type

type HeadlessContentHeaderRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "header";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};
ProofGET /website/_api/headless_pages/2000#/regions/hero/0
{
  "uid": 2000,
  "CType": "textmedia",
  "header": "This page is a TYPO3 page.",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": [/* 2 items */],
  "assets": [/* 1 item */],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Excerpt of the recorded response. Full JSON and type in the proof below.

Proofregions.hero[0]

Request GET /website/_api/headless_pages/2000 #/regions/hero/0 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2000,
  "CType": "textmedia",
  "header": "This page is a TYPO3 page.",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": [
    {
      "_type": "block",
      "_key": "k0",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k1",
          "marks": [],
          "text": "Every sentence here was written in a TYPO3 page tree and delivered as JSON by "
        },
        {
          "_type": "span",
          "_key": "k2",
          "marks": [
            "strong"
          ],
          "text": "tca-api-headless"
        },
        {
          "_type": "span",
          "_key": "k3",
          "marks": [],
          "text": ": composed pages, typed content elements, navigation and SEO meta for any frontend. Each proof shows the request, the JSON and the TypeScript type behind a section."
        }
      ]
    },
    {
      "_type": "block",
      "_key": "k4",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k5",
          "marks": [
            "code"
          ],
          "text": "composer require maikschneider/tca-api-headless:dev-main \\\n  \"maikschneider/tca-api:dev-main as 2.4.0\""
        }
      ]
    }
  ],
  "assets": [
    {
      "uid": 2000,
      "name": "proof-sheet.jpg",
      "extension": "jpg",
      "publicUrl": "/fileadmin/website/proof-sheet.jpg",
      "mimeType": "image/jpeg",
      "fileSize": 109399,
      "metadata": {
        "title": null,
        "description": null
      }
    }
  ],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Generated TypeScript type

type HeadlessContentTextmediaRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "textmedia";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bodytext?: components["schemas"]["PortableText"];
    assets?: components["schemas"]["FileObject"][];
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};

Editors stay in TYPO3

Page tree, backend layouts, content elements and translations work the way editors know them. Nothing changes in the backend: the frontend receives the page as it was composed, as data instead of HTML.

Start with the quick start, or see the same API render the Kettenblatt specimen site.

Proofregions.story[0]

Request GET /website/_api/headless_pages/2000 #/regions/story/0 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2001,
  "CType": "text",
  "header": "Editors stay in TYPO3",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": [
    {
      "_type": "block",
      "_key": "k0",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k1",
          "marks": [],
          "text": "Page tree, backend layouts, content elements and translations work the way editors know them. Nothing changes in the backend: the frontend receives the page as it was composed, as data instead of HTML."
        }
      ]
    },
    {
      "_type": "block",
      "_key": "k4",
      "style": "normal",
      "markDefs": [
        {
          "_key": "k2",
          "_type": "link",
          "href": "https://typo3.example/website/quick-start",
          "target": null,
          "title": null
        },
        {
          "_key": "k3",
          "_type": "link",
          "href": "https://typo3.example/kettenblatt/",
          "target": null,
          "title": "A fictional bicycle workshop"
        }
      ],
      "children": [
        {
          "_type": "span",
          "_key": "k5",
          "marks": [],
          "text": "Start with the "
        },
        {
          "_type": "span",
          "_key": "k6",
          "marks": [
            "k2"
          ],
          "text": "quick start"
        },
        {
          "_type": "span",
          "_key": "k7",
          "marks": [],
          "text": ", or see the same API render the "
        },
        {
          "_type": "span",
          "_key": "k8",
          "marks": [
            "k3"
          ],
          "text": "Kettenblatt specimen site"
        },
        {
          "_type": "span",
          "_key": "k9",
          "marks": [],
          "text": "."
        }
      ]
    }
  ],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Generated TypeScript type

type HeadlessContentTextRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "text";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bodytext?: components["schemas"]["PortableText"];
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};

Frontends get typed data

Content elements arrive in regions, named by the column identifiers of the backend layout. Rich text arrives as Portable Text, bullets as lists, tables as rows. Links are absolute and already point to the right language.

Proofregions.story[1]

Request GET /website/_api/headless_pages/2000 #/regions/story/1 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2006,
  "CType": "text",
  "header": "Frontends get typed data",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": [
    {
      "_type": "block",
      "_key": "k0",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k1",
          "marks": [],
          "text": "Content elements arrive in "
        },
        {
          "_type": "span",
          "_key": "k2",
          "marks": [
            "em"
          ],
          "text": "regions"
        },
        {
          "_type": "span",
          "_key": "k3",
          "marks": [],
          "text": ", named by the column identifiers of the backend layout. Rich text arrives as Portable Text, bullets as lists, tables as rows. Links are absolute and already point to the right language."
        }
      ]
    }
  ],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Generated TypeScript type

type HeadlessContentTextRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "text";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bodytext?: components["schemas"]["PortableText"];
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};

The contract is generated

TCA API describes every resource of a site in an OpenAPI document, including the regions and content types this extension adds. Generate TypeScript types from it and let CI fail when frontend and TYPO3 drift apart. Every type in the proofs on this page was generated that way.

Proofregions.story[2]

Request GET /website/_api/headless_pages/2000 #/regions/story/2 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2007,
  "CType": "text",
  "header": "The contract is generated",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": [
    {
      "_type": "block",
      "_key": "k0",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k1",
          "marks": [],
          "text": "TCA API describes every resource of a site in an OpenAPI document, including the regions and content types this extension adds. Generate TypeScript types from it and let CI fail when frontend and TYPO3 drift apart. Every type in the proofs on this page was generated that way."
        }
      ]
    }
  ],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Generated TypeScript type

type HeadlessContentTextRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "text";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bodytext?: components["schemas"]["PortableText"];
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};

Opt-in per site

Add the site set to every site that should deliver headless pages; sites without it serve none of its resources. A few site settings cover region names, menu depth and content types outside the catalog.

Proofregions.story[3]

Request GET /website/_api/headless_pages/2000 #/regions/story/3 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2008,
  "CType": "text",
  "header": "Opt-in per site",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": [
    {
      "_type": "block",
      "_key": "k0",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k1",
          "marks": [],
          "text": "Add the site set to every site that should deliver headless pages; sites without it serve none of its resources. A few site settings cover region names, menu depth and content types outside the catalog."
        }
      ]
    }
  ],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Generated TypeScript type

type HeadlessContentTextRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "text";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bodytext?: components["schemas"]["PortableText"];
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};

How a page travels

TYPO3
Editors compose the page from content elements in the page tree, in every language of the site.
tca-api-headless
Reads the page through TCA API and answers with JSON: regions, content, navigation and meta.
Your frontend
A static build, a server or an app fetches the page and renders it with generated types.
Proofregions.features[0]

Request GET /website/_api/headless_pages/2000 #/regions/features/0 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2009,
  "CType": "bullets",
  "header": "How a page travels",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bullets_type": 2,
  "bodytext": [
    {
      "term": "TYPO3",
      "definition": "Editors compose the page from content elements in the page tree, in every language of the site."
    },
    {
      "term": "tca-api-headless",
      "definition": "Reads the page through TCA API and answers with JSON: regions, content, navigation and meta."
    },
    {
      "term": "Your frontend",
      "definition": "A static build, a server or an app fetches the page and renders it with generated types."
    }
  ],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Generated TypeScript type

type HeadlessContentBulletsRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "bullets";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bullets_type?: number;
    bodytext?: components["schemas"]["HeadlessBulletList"];
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};

What a response carries

FieldWhat the frontend gets
regionsContent elements, grouped by the column identifiers of the backend layout
bodytextPortable Text, list items or table rows, depending on the content type
header_linkA link object with href, target and title
metaRobots, a canonical URL in the request language and a schema.org WebPage
og_imageAn absolute URL to the processed social image
navigationA menu tree with absolute URLs, limited by a depth setting
?path=The page uid behind a URL path, in the request language
Proofregions.features[1]

Request GET /website/_api/headless_pages/2000 #/regions/features/1 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2002,
  "CType": "table",
  "header": "What a response carries",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": {
    "head": [
      "Field",
      "What the frontend gets"
    ],
    "body": [
      [
        "regions",
        "Content elements, grouped by the column identifiers of the backend layout"
      ],
      [
        "bodytext",
        "Portable Text, list items or table rows, depending on the content type"
      ],
      [
        "header_link",
        "A link object with href, target and title"
      ],
      [
        "meta",
        "Robots, a canonical URL in the request language and a schema.org WebPage"
      ],
      [
        "og_image",
        "An absolute URL to the processed social image"
      ],
      [
        "navigation",
        "A menu tree with absolute URLs, limited by a depth setting"
      ],
      [
        "?path=",
        "The page uid behind a URL path, in the request language"
      ]
    ],
    "foot": []
  },
  "table_caption": "",
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": "",
  "table_header_position": 1
}

Generated TypeScript type

type HeadlessContentTableRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "table";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bodytext?: components["schemas"]["HeadlessTable"];
    table_caption?: string | null;
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
    table_header_position?: number;
};

From composer to the first response

  1. Require the package: composer require maikschneider/tca-api-headless:dev-main "maikschneider/tca-api:dev-main as 2.4.0"
  2. Add the site set maikschneider/tca-api-headless to the dependencies in the site's config.yaml.
  3. Give the columns of your backend layout identifiers such as main. They become the region names.
  4. Request a page: curl https://example.org/_api/headless_pages/1
  5. Write the OpenAPI document of the site and generate types from it:
vendor/bin/typo3 tca-api:openapi main --output openapi.json
bunx openapi-typescript openapi.json -o src/api/schema.d.ts

tca-api-headless is in development. It needs TCA API 2.4 and TYPO3 13.4 or 14.3.

Proofregions.cta[0]

Request GET /website/_api/headless_pages/2000 #/regions/cta/0 Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

{
  "uid": 2090,
  "CType": "text",
  "header": "From composer to the first response",
  "header_layout": 0,
  "header_position": "",
  "header_link": null,
  "subheader": "",
  "bodytext": [
    {
      "_type": "block",
      "_key": "k0",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k1",
          "marks": [],
          "text": "Require the package: "
        },
        {
          "_type": "span",
          "_key": "k2",
          "marks": [
            "code"
          ],
          "text": "composer require maikschneider/tca-api-headless:dev-main \"maikschneider/tca-api:dev-main as 2.4.0\""
        }
      ],
      "listItem": "number",
      "level": 1
    },
    {
      "_type": "block",
      "_key": "k3",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k4",
          "marks": [],
          "text": "Add the site set "
        },
        {
          "_type": "span",
          "_key": "k5",
          "marks": [
            "code"
          ],
          "text": "maikschneider/tca-api-headless"
        },
        {
          "_type": "span",
          "_key": "k6",
          "marks": [],
          "text": " to the dependencies in the site's "
        },
        {
          "_type": "span",
          "_key": "k7",
          "marks": [
            "code"
          ],
          "text": "config.yaml"
        },
        {
          "_type": "span",
          "_key": "k8",
          "marks": [],
          "text": "."
        }
      ],
      "listItem": "number",
      "level": 1
    },
    {
      "_type": "block",
      "_key": "k9",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k10",
          "marks": [],
          "text": "Give the columns of your backend layout identifiers such as "
        },
        {
          "_type": "span",
          "_key": "k11",
          "marks": [
            "code"
          ],
          "text": "main"
        },
        {
          "_type": "span",
          "_key": "k12",
          "marks": [],
          "text": ". They become the region names."
        }
      ],
      "listItem": "number",
      "level": 1
    },
    {
      "_type": "block",
      "_key": "k13",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k14",
          "marks": [],
          "text": "Request a page: "
        },
        {
          "_type": "span",
          "_key": "k15",
          "marks": [
            "code"
          ],
          "text": "curl https://example.org/_api/headless_pages/1"
        }
      ],
      "listItem": "number",
      "level": 1
    },
    {
      "_type": "block",
      "_key": "k16",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k17",
          "marks": [],
          "text": "Write the OpenAPI document of the site and generate types from it:"
        }
      ],
      "listItem": "number",
      "level": 1
    },
    {
      "_type": "block",
      "_key": "k18",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k19",
          "marks": [
            "code"
          ],
          "text": "vendor/bin/typo3 tca-api:openapi main --output openapi.json\nbunx openapi-typescript openapi.json -o src/api/schema.d.ts"
        }
      ]
    },
    {
      "_type": "block",
      "_key": "k20",
      "style": "normal",
      "markDefs": [],
      "children": [
        {
          "_type": "span",
          "_key": "k21",
          "marks": [],
          "text": "tca-api-headless is in development. It needs TCA API 2.4 and TYPO3 13.4 or 14.3."
        }
      ]
    }
  ],
  "layout": 0,
  "frame_class": "default",
  "space_before_class": "",
  "space_after_class": ""
}

Generated TypeScript type

type HeadlessContentTextRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "text";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    bodytext?: components["schemas"]["PortableText"];
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};
Proofregions.cta[1], regions.cta[2], regions.cta[3], regions.cta[4]

Request GET /website/_api/headless_pages/2000 regions.cta[1], regions.cta[2], regions.cta[3], regions.cta[4] Status 200

Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response

JSON response

[
  {
    "uid": 2003,
    "CType": "header",
    "header": "Read the full quick start",
    "header_layout": 0,
    "header_position": "",
    "header_link": {
      "href": "https://typo3.example/website/quick-start",
      "target": null,
      "title": "Five steps to the first request"
    },
    "subheader": "",
    "layout": 0,
    "frame_class": "default",
    "space_before_class": "",
    "space_after_class": ""
  },
  {
    "uid": 2091,
    "CType": "header",
    "header": "Documentation",
    "header_layout": 0,
    "header_position": "",
    "header_link": {
      "href": "https://github.com/maikschneider/tca-api-headless/tree/main/Documentation",
      "target": "_blank",
      "title": "Documentation on GitHub"
    },
    "subheader": "",
    "layout": 0,
    "frame_class": "default",
    "space_before_class": "",
    "space_after_class": ""
  },
  {
    "uid": 2092,
    "CType": "header",
    "header": "GitHub",
    "header_layout": 0,
    "header_position": "",
    "header_link": {
      "href": "https://github.com/maikschneider/tca-api-headless",
      "target": "_blank",
      "title": "Source code on GitHub"
    },
    "subheader": "",
    "layout": 0,
    "frame_class": "default",
    "space_before_class": "",
    "space_after_class": ""
  },
  {
    "uid": 2093,
    "CType": "header",
    "header": "Packagist",
    "header_layout": 0,
    "header_position": "",
    "header_link": {
      "href": "https://packagist.org/packages/maikschneider/tca-api-headless",
      "target": "_blank",
      "title": "maikschneider/tca-api-headless on Packagist"
    },
    "subheader": "",
    "layout": 0,
    "frame_class": "default",
    "space_before_class": "",
    "space_after_class": ""
  }
]

Generated TypeScript type

type HeadlessContentHeaderRead = {
    "@type"?: string;
    "@id"?: string;
    uid?: number;
    CType: "header";
    header?: string;
    header_layout?: number;
    header_position?: string;
    header_link?: components["schemas"]["HeadlessLink"] | null;
    subheader?: string;
    layout?: number;
    frame_class?: string;
    space_before_class?: string;
    space_after_class?: string;
};