How to make a read-only JSON REST API using Jekyll and some builtin templating features in Jekyll 3 or 4.
This is useful if you have content in your pages which you want to make available to an external service or a JavaScript single-page application that reads from your API backend.
The headers also get set correctly by using .json instead of .md or .html as the source files.
Content-Type application/json
- JSON on Wikipedia
- API on Wikipedia
- Representational state transfer
See also Data files in the Jekyll docs. You might iterate over data in a JSON or YAML file or files to build up output on a page. The data files are your database and then Jekyll builds your API. This is also a way to build a databse JSON file to be consumed on the frontend such as for search functionality.
Or you might store your data in the frontmatter of Jekyll Collections which get outputted as pages similar to the Page example below. That way you can group your JSON data into collections as interate over them easily.