Simple REST-full FS-backed document storage.
It utilises REST, JSON-patch and JSONpath for data manipulation and querying.
Uses local file system (json files) for persistence.
Clone repo
git clone https://github.com/Beh01der/skyconf.git
Build
cd skyconf
yarn
yarn build
Start
node dist/index.js
docker run -d --name my-skyconf -p 3000:3000 beh01der/skyconf
Map local data directory for persistence
docker run -d --name my-skyconf -p 3000:3000 -v ~/Tmp/my-skyconf:/app/data beh01der/skyconf
Configuration can be done by environment variables.
- SKYCONF_PORT =
3000
- port to run service on - SKYCONF_DATA_DIR =
./data
- data directory for stored documents - SKYCONF_UNSAFE_REMOVE_DIR =
false
- when set totrue
will userm -rf
- like method when removing non-empty directories (will remove such directories with their content)
GET /api/v1/storage[resource path]
- returns a single document or list of documents depending on the resource.
Parameters:
- jsonpath - (optional) - jsonpath query selector. Example:
$.name
More details on jsonpath can be found here https://github.com/JSONPath-Plus/JSONPath
Example 1 - document :
curl -vg http://localhost:3000/api/v1/storage/my-first-item.json
returns
{ "result": "success", "doc": { "id": 1, "name": "Item 1" } }
Example 2 - document with jsonpath query :
curl -vg http://localhost:3000/api/v1/storage/my-first-item.json?jsonpath=$.name
returns
{ "result": "success", "doc": ["Item 1"] }
Example 3 - directory:
curl -vg http://localhost:3000/api/v1/storage
returns
{
"result": "success",
"isDirectory": true,
"docs": [{ "name": "my-first-item.json" }]
}
Example 4 - error:
curl -vg http://localhost:3000/api/v1/storage/items
returns
{
"result": "error",
"message": "Entity not found",
"path": "/api/v1/storage/items"
}
POST /api/v1/storage[resource path]
- creates new document or replaces existing one. Will create missing directories if needed.
Example 1:
curl -v -XPOST -H 'Content-Type: application/json' -d '{"id": 1, "name":"Item 1"}' http://localhost:3000/api/v1/storage/my-first-item.json
returns
{ "result": "success", "doc": { "id": 1, "name": "Item 1" } }
PATCH /api/v1/storage[resource path]
- updates existing document and returns result.
More details on "json-patch" format here https://github.com/Starcounter-Jack/JSON-Patch and https://datatracker.ietf.org/doc/html/rfc6902
Parameters:
- format - (optional - default = json) -
json|json-patch
defines format of the patch
Example 1 - using json (default) format:
curl -vg curl -v -XPATCH -H 'Content-Type: application/json' -d '{"sub-items":[]}' http://localhost:3000/api/v1/storage/my-first-item.json
returns
{ "result": "success", "doc": { "id": 1, "name": "Item 1", "sub-items": [] } }
Example 2 using json-patch format:
curl -v -XPATCH -H 'Content-Type: application/json' \
-d '[{"op":"add","path":"/sub-items/-","value":"one"},{"op":"add","path":"/description","value":"Item 1 description"}]' \
http://localhost:3000/api/v1/storage/my-first-item.json?format=json-patch
returns
{
"result": "success",
"doc": {
"id": 1,
"name": "Item 1",
"sub-items": ["one"],
"description": "Item 1 description"
}
}
DELETE /api/v1/storage[resource path]
- removes specified document or directory.
Example 1:
curl -v -XDELETE http://localhost:3000/api/v1/storage/my-first-item.json
returns
{ "result": "success" }