Mecha CMS

Custom site appearance.

JSON

Table of Contents
  1. Usage 
  2. Supported Parameters 
  3. URL Examples 
  4. JavaScript Example 

A layout system that outputs JSON data instead of HTML page. Useful for those who want to use Mecha as a headless CMS.

Download Stable Version Download Development Version

Something looks broken? We accept bounties to fix them faster.

^64 Downloads
v1.1.028 Downloads
v1.0.070 Downloads

A headless CMS is a back-end only content management system built from the ground up as a content repository that makes content accessible via a RESTful API for display on any device. The term “headless” comes from the concept of chopping the “head” (the front end, i.e. the website) off the “body” (the back end, i.e. the content repository).

Usage 

Accessing regular page URL will produce a JSON output, so you can process that using third-party services. The output will be cached for a day unless you add a ?cache=0 parameter to the URL. The following is an example output of a single page:

{
  "are": { … },
  "can": { … },
  "description": "Site description.",
  "generator": "Mecha 2.6.0",
  "has": { … },
  "is": {
    "page": true,
    …
  },
  "not": { … },
  "page": {
    "description": "Page description.",
    "id": "1577813996",
    "link": null,
    "time": "2020-01-01 00:39:56",
    "title": "Page Title",
    "url": "https://mecha-cms.com/article/page-name",
    "x": "page"
  },
  "status": 200,
  "t": "Page Title | Site Title",
  "title": "Site Title",
  "url": {
    "current": "https://mecha-cms.com/article/page-name",
    "next": "https://mecha-cms.com/article/page-name-2",
    "prev": null
  }
}

Supported Parameters 

NameDescription
cacheSet to a value that can be evaluated to false to disable the cache.
tokenTODO: Make your data private by adding a mandatory access token.
siteList your properties (separated by commas) that you want them to be available in the JSON output, taken from the $site variable.
pageList your page properties (separated by commas) that you want them to be available in the JSON output.
pagesList your page properties (separated by commas) of the pages that you want them to be available in the JSON output.
tagList your tag properties (separated by commas) that you want them to be available in the JSON output.

URL Examples 

https://mecha-cms.com/article/1?page=title,description,content,time&pages=title,description,time,url,link
https://mecha-cms.com/article/page-name?page=title,description,time,content

JavaScript Example 

<script>
fetch('https://mecha-cms.com/article/page-name').then(response => {
    if (!response.ok) {
        // …
    }
    return response.json();
}).then(json => {
    console.log(json);
});
</script>

0 Comments

No comments yet.