![]()
tupplur
Create a quick rest api with JSON schema. Based on deno kv for storage and ajv for validation.
run locally
Install
deno install -n tupplur --allow-net --allow-read --allow-write --allow-env --unstable https://deno.land/x/tupplur/local.tsWhy all these permissions?
--allow-netto accept incoming requests--allow-readto read the database--allow-writeto write to the database--allow-envto read the.envfile--unstablebecause deno kv still is
Create an .env file like this
SUPER_USER_KEY=hard_to_guess_string
DB_PATH=test.db
PORT=3333SUPER_USER_KEYis what you are going to use to authenticate when managing collectionsDB_PATHis where the data is going to be saved (if not defined, will use global deno kv store)PORTthe port on which the service runs (defaults to 3333)
Start the server
tupplurcreate your first collection
Make a POST request to /collections with name (string) and schema (the
JSON schema) in the body and Authentication: Bearer $SUPER_USER_KEY in the
headers.
manage access to the collection
Make a POST request to /collections/:name/access, with the same authentication
and a body like:
{
"key": "public",
"get": true,
"post": true,
"patch": true,
"put": true,
"delete": true
}This will allow anyone to make get, post, patch, put and delete
requests to /api/:name endpoints. Restrict by omiting methods or setting them
to false. By default only the super user has access to the endpoints.
The key public means the users do not need to be authenticated. If you want to
use it with other keys than SUPER_USER_KEY but still not it being public, use
whatever hard to guess string instead of public and use that in the
authentication header. You can have multiple keys with different access.
see the example requests for more endpoints to manage collections.
use the api
Start the server and go to http://localhost:3333 (if you did not change the port) to see and try the available endpoints.
run on deno deploy
Create a project in https://dash.deno.com/projects
Add a SUPER_USER_KEY environment variable to manage collections.
Run:
deployctl deploy --project YOUR_PROJECT_NAME --token=YOUR_TOKEN deploy.ts