Skip to content

cloud-cli/json-store

Repository files navigation

JSON store

How to run

From source:

npm i && npm run build && npm start

Via Docker:

docker run --rm -d -p 80:1234 -e PORT=1234 ghcr.io/cloud-cli/json-store:latest

Using as an ESM Module

import { Store } from 'https://server-address.io/index.mjs';

// create a store on server
const storeId = await Store.create();

// consume a store
const store = Store.get('__your_store_id__');
const users = await store.getResource('users');

// add resource
await users.add({ uid: '123', name: 'Joe' });

// remove it
await users.remove('123');

// get one
await users.get('123');

// list all
await users.list();

As an API

Create a database:

curl 'https://server-address.io/new'

{
  "id": "cdc0cafc15b857a2a61d292c0a30359091f57c9bc430f0785d0ed564f0b1fb9b"
}

PUT

The following command will create a user in /user/123:

curl -XPOST -H "Content-type: application/json" -d '{ "name": "John Doe" }' 'https://server-address.io/cdc0cafc15b857a2a61d292c0a30359091f57c9bc430f0785d0ed564f0b1fb9b/user/123'

GET

The following command will retrieve the user we created earlier:

curl 'https://server-address.io/cdc0cafc15b857a2a61d292c0a30359091f57c9bc430f0785d0ed564f0b1fb9b/user/123'

DELETE

The following command will delete the user:

curl -XDELETE 'https://server-address.io/cdc0cafc15b857a2a61d292c0a30359091f57c9bc430f0785d0ed564f0b1fb9b/user/123'

Env Variables

Variable Description
PORT http port where the service runs
STORAGE Type of storage to use. "memory", "file", "sqlite"
FILE_PATH /path/to/folder where files will be stored if 'file' storage is used
SQLITE_PATH Path to db file if 'sqlite' storage is used
DEBUG Set to any truthy value to enable debug logging