-
Notifications
You must be signed in to change notification settings - Fork 0
Endpoints
Data is made available through the API. This is the only interface of emmer.
Health check endpoint, accepts all methods.
Takes POST requests, writes current cache to the filesystem.
Send DELETE request here to remove all cache (and free memory).
This endpoint is based on your JSON structure. So the example below is for CRUD-ing [key1][key2] in file.json. The value (which can be anything) is then added to the body of the request.
DELETE/PUT/GET: /api/file/key1/key2/...
Note, the first step (after /api/) refers to the file, the steps thereafter refer to the json path. However, you can also create a folder path before you access the json file itself. For this, use '--' to create folder steps. For example, GET '/api/file--with--path/test/0' will access '[test][0]' for the file 'file/with/path.json'.
You can add data with different modes. By default, it will be add/overwrite. However, you can also append (if it's an array) or increment (if it's a number) values. This is done by setting the 'mode' parameter when doing a PUT request.
If you access a list, you can append the value (that's currently in your request body) to that list by setting mode=append. For example, we start with the following JSON file. I.e., we have an article object that a website can render.
{
"article1": {
"title": "The witch man",
"text": "A great story about a man with two swords.",
"comments": []
}
}Next, a comment can be added by sending the following body to /api/article1/comments?mode=append add a comment. Note, you can keep sending PUT requests to this endpoint to add comments.
{"text": "great job!", "username": "timo"}Increment mode in/decreases a numeric value. By default, increases a value by 1. If you have a numeric value in the body, then that is used instead.
Using mode 'fs' is only relevant for GET request (very complex I know) if you don't want to read from cache, but instead directly from the filesystem. Also updates the cache.