Quick start
Five steps to typed JSON
From an existing TYPO3 site to a typed response. Every request on this page ran against this site's TYPO3 instance while the page was built; the recorded response sits under it.
Proofregions.main[0]
Request GET / #/regions/main/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": 2010,
"CType": "text",
"header": "Five steps to typed JSON",
"header_layout": 0,
"header_position": "",
"header_link": null,
"subheader": "",
"bodytext": [
{
"_type": "block",
"_key": "k0",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k1",
"marks": [],
"text": "From an existing TYPO3 site to a typed response. Every request on this page ran against this site's TYPO3 instance while the page was built; the recorded response sits under it."
}
]
}
],
"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;
};Require the package
composer require maikschneider/tca-api-headless:dev-main \
"maikschneider/tca-api:dev-main as 2.4.0" It brings TCA API 2.4 or later and runs on TYPO3 13.4 and 14.3. Both are in development: until their stable releases, use the explicit constraints above. Install EXT:seo (typo3/) for the SEO fields of pages.
Proofregions.main[1]
Request GET / #/regions/main/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": 2016,
"CType": "text",
"header": "Require the package",
"header_layout": 0,
"header_position": "",
"header_link": null,
"subheader": "",
"bodytext": [
{
"_type": "block",
"_key": "k0",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k1",
"marks": [
"code"
],
"text": "composer require maikschneider/tca-api-headless:dev-main \\\n \"maikschneider/tca-api:dev-main as 2.4.0\""
}
]
},
{
"_type": "block",
"_key": "k3",
"style": "normal",
"markDefs": [
{
"_key": "k2",
"_type": "link",
"href": "https://github.com/maikschneider/tca-api",
"target": "_blank",
"title": "TCA API on GitHub"
}
],
"children": [
{
"_type": "span",
"_key": "k4",
"marks": [],
"text": "It brings "
},
{
"_type": "span",
"_key": "k5",
"marks": [
"k2"
],
"text": "TCA API"
},
{
"_type": "span",
"_key": "k6",
"marks": [],
"text": " 2.4 or later and runs on TYPO3 13.4 and 14.3. Both are in development: until their stable releases, use the explicit constraints above. Install EXT:seo ("
},
{
"_type": "span",
"_key": "k7",
"marks": [
"code"
],
"text": "typo3/cms-seo"
},
{
"_type": "span",
"_key": "k8",
"marks": [],
"text": ") for the SEO fields of pages."
}
]
}
],
"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;
};Add the site set
Add the set to every site that should deliver headless pages; it includes TCA API's set. Sites without it serve none of the extension's resources. This is the config.yaml of the site you are reading:
dependencies:
- maikschneider/tca-api-headless A few site settings change the defaults. This site's settings.yaml:
tca_api_headless:
navigation:
depth: 2
maxDepth: 4
fallbackCTypes: []Proofregions.main[2]
Request GET / #/regions/main/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": 2017,
"CType": "text",
"header": "Add the site set",
"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 set to every site that should deliver headless pages; it includes TCA API's set. Sites without it serve none of the extension's resources. This is the "
},
{
"_type": "span",
"_key": "k2",
"marks": [
"code"
],
"text": "config.yaml"
},
{
"_type": "span",
"_key": "k3",
"marks": [],
"text": " of the site you are reading:"
}
]
},
{
"_type": "block",
"_key": "k4",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k5",
"marks": [
"code"
],
"text": "dependencies:\n - maikschneider/tca-api-headless"
}
]
},
{
"_type": "block",
"_key": "k6",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k7",
"marks": [],
"text": "A few site settings change the defaults. This site's "
},
{
"_type": "span",
"_key": "k8",
"marks": [
"code"
],
"text": "settings.yaml"
},
{
"_type": "span",
"_key": "k9",
"marks": [],
"text": ":"
}
]
},
{
"_type": "block",
"_key": "k10",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k11",
"marks": [
"code"
],
"text": "tca_api_headless:\n navigation:\n depth: 2\n maxDepth: 4\n fallbackCTypes: []"
}
]
}
],
"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;
};Look up a path
A frontend knows the URL. The lookup turns its path into the page's uid:
curl -H 'Accept: application/ld+json' 'https://example.org/_api/headless_pages?path=/quick-start' Response 200GET /website/_api/headless_pages?path=/quick-start
Request GET / Status 200
Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response
JSON response
{
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
"@type": "hydra:Collection",
"@id": "/_api/headless_pages",
"hydra:totalItems": 1,
"hydra:member": [
{
"@type": "HeadlessPages",
"@id": "/_api/headless_pages/2001",
"uid": 2001
}
],
"hydra:view": {
"@type": "hydra:PartialCollectionView",
"hydra:first": "/_api/headless_pages?path=%2Fquick-start&page=1",
"hydra:last": "/_api/headless_pages?path=%2Fquick-start&page=1",
"hydra:previous": null,
"hydra:next": null
}
}Generated TypeScript type
type HeadlessPagesCollection = {
"@context"?: string;
"@type"?: string;
"@id"?: string;
"hydra:totalItems"?: number;
"hydra:member"?: components["schemas"]["HeadlessPagesLookup"][];
"hydra:view"?: {
"@type"?: string;
"hydra:first"?: string;
"hydra:last"?: string;
"hydra:previous"?: string | null;
"hydra:next"?: string | null;
};
"hydra:search"?: {
"@type"?: string;
"hydra:template"?: string;
"hydra:variableRepresentation"?: string;
"hydra:mapping"?: {
"@type"?: string;
variable?: string;
property?: string;
required?: boolean;
}[];
};
redirect?: components["schemas"]["HeadlessPagesRedirect"];
};Proofregions.main[3]
Request GET / #/regions/main/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": 2018,
"CType": "text",
"header": "Look up a path",
"header_layout": 0,
"header_position": "",
"header_link": null,
"subheader": "",
"bodytext": [
{
"_type": "block",
"_key": "k0",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k1",
"marks": [],
"text": "A frontend knows the URL. The lookup turns its path into the page's "
},
{
"_type": "span",
"_key": "k2",
"marks": [
"code"
],
"text": "uid"
},
{
"_type": "span",
"_key": "k3",
"marks": [],
"text": ":"
}
]
},
{
"_type": "block",
"_key": "k4",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k5",
"marks": [
"code"
],
"text": "curl -H 'Accept: application/ld+json' 'https://example.org/_api/headless_pages?path=/quick-start'"
}
]
}
],
"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;
};Request the page
The page brings its SEO fields, a meta object for the head and its content elements, grouped by region:
curl -H 'Accept: application/ld+json' 'https://example.org/_api/headless_pages/2001' Response 200GET /website/_api/headless_pages/2001
Request GET / Status 200
Recorded at build time from TYPO3 14.3. Host replaced with typo3.example; the data is unchanged. Full JSON response
JSON response
{
"@type": "HeadlessPages",
"@id": "/_api/headless_pages/2001",
"uid": 2001,
"title": "Quick start",
"slug": "/quick-start",
"seo_title": "",
"description": "From composer require to the first typed request, with the output of every step.",
"no_index": 0,
"no_follow": 0,
"canonical_link": null,
"og_title": "",
"og_description": null,
"og_image": [],
"breadcrumbs": [
{
"uid": 2000,
"title": "tca-api-headless",
"nav_title": "",
"url": "https://typo3.example/website/",
"doktype": 1
},
{
"uid": 2001,
"title": "Quick start",
"nav_title": "",
"url": "https://typo3.example/website/quick-start",
"doktype": 1
}
],
"languages": [
{
"languageId": 0,
"locale": "en-US",
"hreflang": "en",
"title": "English",
"url": "https://typo3.example/website/quick-start",
"available": true,
"active": true
},
{
"languageId": 1,
"locale": "de-DE",
"hreflang": "de",
"title": "German",
"url": "https://typo3.example/website/de/schnellstart",
"available": true,
"active": false
}
],
"meta": {
"robots": "index,follow",
"canonical": "https://typo3.example/website/quick-start",
"schema": {
"@context": "https://schema.org",
"@type": "WebPage",
"url": "https://typo3.example/website/quick-start",
"name": "Quick start",
"inLanguage": "en",
"description": "From composer require to the first typed request, with the output of every step."
},
"alternates": [
{
"hreflang": "en",
"href": "https://typo3.example/website/quick-start"
},
{
"hreflang": "de",
"href": "https://typo3.example/website/de/schnellstart"
},
{
"hreflang": "x-default",
"href": "https://typo3.example/website/quick-start"
}
]
},
"regions": {
"main": [/* 6 elements */],
"aside": [/* 3 elements */]
}
}Generated TypeScript type
type HeadlessPagesRead = {
"@type"?: string;
"@id"?: string;
uid?: number;
title?: string;
slug?: string | null;
seo_title?: string;
description?: string | null;
no_index?: number;
no_follow?: number;
canonical_link?: components["schemas"]["HeadlessLink"] | null;
og_title?: string;
og_description?: string | null;
og_image?: components["schemas"]["FileObject"][];
breadcrumbs: components["schemas"]["HeadlessPagesBreadcrumb"][];
languages: components["schemas"]["HeadlessPagesLanguage"][];
meta: components["schemas"]["HeadlessPagesMeta"];
regions: {
[key: string]: components["schemas"]["HeadlessContentRead"][];
};
shortcut?: components["schemas"]["HeadlessPagesShortcut"] | null;
};Proofregions.main[4]
Request GET / #/regions/main/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": 2019,
"CType": "text",
"header": "Request the 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": "The page brings its SEO fields, a "
},
{
"_type": "span",
"_key": "k2",
"marks": [
"code"
],
"text": "meta"
},
{
"_type": "span",
"_key": "k3",
"marks": [],
"text": " object for the head and its content elements, grouped by region:"
}
]
},
{
"_type": "block",
"_key": "k4",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k5",
"marks": [
"code"
],
"text": "curl -H 'Accept: application/ld+json' 'https://example.org/_api/headless_pages/2001'"
}
]
}
],
"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;
};Generate the types
The site's OpenAPI document describes every response. Generate TypeScript from it and compare it in CI:
curl -o openapi.json 'https://example.org/_api/openapi.json'
bunx openapi-typescript openapi.json -o src/api/schema.d.ts Content elements then narrow on CType:
import type { components } from './api/schema';
type Page = components['schemas']['HeadlessPagesRead'];
const base = 'https://example.org';
const headers = { Accept: 'application/ld+json' };
const lookup = await (await fetch(`${base}/_api/headless_pages?path=/quick-start`, { headers })).json();
const page: Page = await (await fetch(`${base}/_api/headless_pages/${lookup['hydra:member'][0].uid}`, { headers })).json();
for (const content of page.regions.aside ?? []) {
if (content.CType === 'table') console.log(content.bodytext?.body); // string[][]
} Proofregions.main[5]
Request GET / #/regions/main/5 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": 2220,
"CType": "text",
"header": "Generate the types",
"header_layout": 0,
"header_position": "",
"header_link": null,
"subheader": "",
"bodytext": [
{
"_type": "block",
"_key": "k0",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k1",
"marks": [],
"text": "The site's OpenAPI document describes every response. Generate TypeScript from it and compare it in CI:"
}
]
},
{
"_type": "block",
"_key": "k2",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k3",
"marks": [
"code"
],
"text": "curl -o openapi.json 'https://example.org/_api/openapi.json'\nbunx openapi-typescript openapi.json -o src/api/schema.d.ts"
}
]
},
{
"_type": "block",
"_key": "k4",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k5",
"marks": [],
"text": "Content elements then narrow on "
},
{
"_type": "span",
"_key": "k6",
"marks": [
"code"
],
"text": "CType"
},
{
"_type": "span",
"_key": "k7",
"marks": [],
"text": ":"
}
]
},
{
"_type": "block",
"_key": "k8",
"style": "normal",
"markDefs": [],
"children": [
{
"_type": "span",
"_key": "k9",
"marks": [
"code"
],
"text": "import type { components } from './api/schema';\n\ntype Page = components['schemas']['HeadlessPagesRead'];\nconst base = 'https://example.org';\nconst headers = { Accept: 'application/ld+json' };\n\nconst lookup = await (await fetch(`${base}/_api/headless_pages?path=/quick-start`, { headers })).json();\nconst page: Page = await (await fetch(`${base}/_api/headless_pages/${lookup['hydra:member'][0].uid}`, { headers })).json();\n\nfor (const content of page.regions.aside ?? []) {\n if (content.CType === 'table') console.log(content.bodytext?.body); // string[][]\n}"
}
]
}
],
"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;
};In short
- Require maikschneider/tca-api-headless
- Add the site set to the site
- Look up the path of a page
- Request the page by uid
- Generate types from openapi.json
Proofregions.aside[0]
Request GET / #/regions/aside/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": 2011,
"CType": "bullets",
"header": "In short",
"header_layout": 0,
"header_position": "",
"header_link": null,
"subheader": "",
"bullets_type": 1,
"bodytext": [
"Require maikschneider/tca-api-headless",
"Add the site set to the site",
"Look up the path of a page",
"Request the page by uid",
"Generate types from openapi.json"
],
"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;
};Requirements
| TYPO3 | 13.4 or 14.3 |
|---|---|
| PHP | 8.2 or later |
| TCA API | 2.4 or later |
| EXT:seo | for the SEO fields |
Proofregions.aside[1]
Request GET / #/regions/aside/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": 2012,
"CType": "table",
"header": "Requirements",
"header_layout": 0,
"header_position": "",
"header_link": null,
"subheader": "",
"bodytext": {
"head": [],
"body": [
[
"TYPO3",
"13.4 or 14.3"
],
[
"PHP",
"8.2 or later"
],
[
"TCA API",
"2.4 or later"
],
[
"EXT:seo",
"for the SEO fields"
]
],
"foot": []
},
"table_caption": "From the installation guide",
"layout": 0,
"frame_class": "default",
"space_before_class": "",
"space_after_class": "",
"table_header_position": 2
}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;
};Downloads
- cheat-sheet.txt1 KBEvery request of the extension on one page
- quick-start.txt1 KBThe quick start as plain text
- quick start.txt1 KBThe same file, with a space in its name
Proofregions.aside[2]
Request GET / #/regions/aside/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": 2013,
"CType": "uploads",
"header": "Downloads",
"header_layout": 0,
"header_position": "",
"header_link": null,
"subheader": "",
"media": [
{
"uid": 2026,
"name": "cheat-sheet.txt",
"extension": "txt",
"publicUrl": "/fileadmin/website/cheat-sheet.txt",
"mimeType": "text/plain",
"fileSize": 632,
"metadata": {
"title": null,
"description": "Every request of the extension on one page"
}
},
{
"uid": 2001,
"name": "quick-start.txt",
"extension": "txt",
"publicUrl": "/fileadmin/website/quick-start.txt",
"mimeType": "text/plain",
"fileSize": 606,
"metadata": {
"title": null,
"description": "The quick start as plain text"
}
},
{
"uid": 2013,
"name": "quick start.txt",
"extension": "txt",
"publicUrl": "/fileadmin/website/quick%20start.txt",
"mimeType": "text/plain",
"fileSize": 606,
"metadata": {
"title": null,
"description": "The same file, with a space in its name"
}
}
],
"layout": 0,
"frame_class": "default",
"space_before_class": "",
"space_after_class": ""
}Generated TypeScript type
type HeadlessContentUploadsRead = {
"@type"?: string;
"@id"?: string;
uid?: number;
CType: "uploads";
header?: string;
header_layout?: number;
header_position?: string;
header_link?: components["schemas"]["HeadlessLink"] | null;
subheader?: string;
media?: components["schemas"]["FileObject"][];
layout?: number;
frame_class?: string;
space_before_class?: string;
space_after_class?: string;
};