Syntax used in the configuration file.
Let’s start with an example and then let’s decompose the keys:
{
"robots": true,
"sitemap": true,
"static_txt_content": [
"hello.txt"
],
"pages":[
{
"name": "post",
"URLPattern": "/posts/:post",
"BackendURLPattern": "https://jsonplaceholder.typicode.com/posts/:post",
"Template": "post",
"Layout": "main",
"CacheTTL": "3600s"
},
{
"name": "home",
"URLPattern": "/",
"BackendURLPattern": "https://jsonplaceholder.typicode.com/posts",
"Template": "home",
"Layout": "main",
"CacheTTL": "3600s",
"IsArray": true,
"extra": {"is_home":true }
}
],
"templates": {"home":"home.mustache","post":"post.mustache"},
"layouts": {"main":"main_layout.mustache"},
"extra":{
"lang": "en-US",
"copyright": "© 2018 My Company"
},
"public_folder": {
"path_to_folder": "./public",
"url_prefix": "/"
}
}
robots
(boolean): When set to true automatically creates the route /robots.txt
using the static file with the same name.sitemap
(boolean): When set to true automatically creates the route /sitemaps.xml
using the static file with the same name.static_txt_content
(list): Static content that will be served when present in the static
folder.pages
(list): List of page objects that API2HTML will process and rendertemplates
(key-value): List of template names and filename. The name is used in the page definition and the value is the relative path to the file.layouts
(key-value): List of layouts available names and filename. The layout loads the surrounding content so you only need to declare the inner content in each template. Layouts usually contain headers, footers and similar content.extra
(key-value): List of additional variables that will be available across all templates under {{ extra.key }}
public_folder
(optional struct): If defined, the files and folders at path_to_folder
will be served at the prefix url_prefix
.When declaring pages
in the root the page object accepts the following attributes:
name
: A friendly identifier for your page. Letters only, no spaces.
URLPattern
: The URL where API2HTML will listen. You can use variables using colons ( :var
)
BackendURLPattern
: The API call that will be executed and injected inside the {{ Data }}
variable. You can use the variables declared in URLPattern
Template
: The template name as defined in the templates
attribute
Layout
: The layout that will encapsulate the template, as defined in the layouts
attribute.
CacheTTL
(string): Time for the Cache-Control
header added to the responses. Use s
for seconds, h
hours, m
for minutes. E.g: 4h
The order of appearance of the pages is very important, as if you have conflicting routes the behavior might not be the one you expect. When handling routes that share a part of the pattern, always declare the most specific case first and go down to the most generalist. E.g:
/posts/:postid/detail
/posts/:postid
/posts
/
Continue to Templates →
← Back to Creating your first site