Developer Guide to Document Authoring with Edge Delivery Services. Part 6

Author: Tom Cranstoun

Json and GitHub

A bit more info on Json, using GitHub as a fallback for sheets

This is part 6 of my Developer’s Guide to Document Authoring with Edge Delivery Services; this time, we will investigate Json and The GitHub connection.

Previously

We created a SPA app using Documents as the data source and a document with ReactJS to serve the content.

Part 6 - Json and Github

Edge Delivery Services can create an index of published material; one uses a Google sheet/ Microsoft Excel sheet to do this work. Full details here Indexing (www.aem.live)

If we provide the blank query index in the notes folder, they are entered into the sheet as shown when Edge Delivery Servies creates published pages.

Then the json is produced by the url main--allaboutv2--ddttom.hlx.live/notes/query-index.json

{
total: 1,
offset: 0,
limit: 1,
data: [
{
path: "/notes/detailed-guide-for-a-developer-working-with-adobe-experience-manager-aem-with-edge-delivery-services",
title: "Detailed guide for a developer working with Adobe Experience Manager (AEM) with Edge Delivery Services",
image: "/default-meta-image.png?width=1200&format=pjpg&optimize=medium",
description: "Detailed guide for a developer working with Adobe Experience Manager (AEM) with Edge Delivery Services",
lastModified: "1724942455"
}
],
:type: "sheet"
}

We discussed all of this in an earlier article, in part 3.

The critical thing to note is the structure of the json returned from the sheet; we can create json from a sheet by creating titles and cell entries like this.

This, in turn, will provide simple json

{
total: 3,
offset: 0,
limit: 3,
data: [
{
url: "/fragments/*",
key: "access-control-allow-origin",
value: "*"
},
{
url: "/blocks/carousel/*",
key: "access-control-allow-origin",
value: "*"
},
{
url: "/blocks/example/*",
key: "access-control-allow-origin",
value: "*"
}
],
:type: "sheet"
}

In edge delivery services, any json that is provided in the root folder with the path name of header.json is applied to the website. Edge Delivery Services will use these headers for the paths mentioned in the url element. Note the wildcard. Custom HTTP Response Headers (www.aem.live)

You may not want to give content authors complete control over the headers; it is a complex subject with wildcarding and key/value entries. I suggest making this a developer's responsibility.

If you create a matching headers.json in your code editor and add it to the GitHub root folder, then GitHub will be used if the sheet has yet to be created. The beauty of Edge Delivery services is that if the user is technical and aware of the technique to create their sheet, they can do so, and their version of the json will override the developer-provided one. I use this technique in my development of Edge Delivery Services Projects.

I have configuration information in a file named /config/defaults.json in my GitHub.

I have kept the generated JSON original layout as if I had created it on a sheet. However, I have changed the type to ‘fallback’ so that I can debug it later.


If we need to change things on production without releasing new code, we just have to create a new sheet named defaults with all the information, including the changes and then publish it.

Other sheets used in Edge Delivery Services are

Metadata (Bulk Metadata (www.aem.live))

Redirects (Redirects (www.aem.live))

Config (Project Configuration (www.aem.live)) is a particular item in a special folder. It cannot be served on the web and cannot be previewed.

/fragments/ddt/proposition

Related Articles

guide
Back to Top