Database as a service

At its core, StaticBackend’s primary offering is a database as a service allowing you to perform CRUD operations. Here’s how to manage your user’s data.

Indexed per account by default

Each repository you’ll create will always have an accountId field, which is an index for performance reasons and security.

This accountId is automatically set for you from the authenticated user’s information.

Public repository

Sometimes you need repositories that can be read by all your users. Editing and deleting a record is only allowed for the account creator.

Prefixing the name of the repository with pub_ will turn a repository as public. Note that users still need to be authenticated to read public repositories.

We do not support unauthenticated read at this moment.

Create a document

Adds a document to a repository.

HTTP request:

POST /db/{repository-name}

Format: JSON

Body:

Your JSON will be stored as-is with the addition of an id and accountId fields.

Example:

curl -H "Content-Type: application/json" \
     -H "SB-PUBLIC-KEY: your-pub-key" \
     -H "Authorization: Bearer user-token" \
     -X POST \
     -d '{"name": "task name", "done": false}' \
     https://na1.staticbackend.com/db/tasks

Response:

{
	"accountId":"5e184d95b1374eaf8b994bf3",
	"done":false,
	"id":"5e185aceb1374eaf8b994bf6",
	"name":"task name"
}

List documents

List documents for a repository.

HTTP request:

GET /db/{repository-name}

Querystring parameters:

name type description
page number Result page (starting at 1, default to 1)
size number How many document per page (maximum 100, default to 25)
desc bool Get result by descending order of creation (default to ascending)

Example:

curl -H "Content-Type: application/json" \
     -H "SB-PUBLIC-KEY: your-pub-key" \
     -H "Authorization: Bearer user-token" \
     https://na1.staticbackend.com/db/tasks?size=2&desc=true

Response:

{
	"page":1,
	"size":2,
	"total":223,
	"results":[{
		"accountId":"5e184d95b1374eaf8b994bf3",
		"done":true,
		"id":"5e185bdcb1374eaf8b994bf7",
		"name":"2nd task here"
	},{
		"accountId":"5e184d95b1374eaf8b994bf3",
		"done":false,
		"id":"5e185aceb1374eaf8b994bf6",
		"name":"task name here"
	}]
}

Get a document

Fetch for a specific document.

HTTP request:

GET /db/{repository-name}/{doc-id}

Example:

curl -H "Content-Type: application/json" \
     -H "SB-PUBLIC-KEY: your-pub-key" \
     -H "Authorization: Bearer user-token" \
     https://na1.staticbackend.com/db/tasks/5e185aceb1374eaf8b994bf6

Response:

{
	"accountId":"5e184d95b1374eaf8b994bf3",
	"done":false,
	"id":"5e185aceb1374eaf8b994bf6",
	"name":"task name here"
}

Query for documents

Get specific documents by supplying criterias.

HTTP request:

POST /query/{repository-name}

Format: JSON

Querystring parameters:

name type description
page number Result page (starting at 1, default to 1)
size number How many document per page (maximum 100, default to 25)
desc bool Get result by descending order of creation (default to ascending)

Body:

name type description
field string The field name.
op string Operator, one of (==, !=, >, <, >=, <=, in, !in)
value any Filter field on that value based on operator.

This should be formatted like this:

[
	["done", "==", true],
	["field", "!=", "value"]
]

Example:

curl -H "Content-Type: application/json" \
     -H "SB-PUBLIC-KEY: your-pub-key" \
     -H "Authorization: Bearer user-token" \
     -X POST
     -d '[["done", "==", true]]'
     https://na1.staticbackend.com/query/tasks

Response:

{
	"page":1,
	"size":25,
	"total":1,
	"results":[{
		"accountId":"5e184d95b1374eaf8b994bf3",
		"done":true,
		"id":"5e185bdcb1374eaf8b994bf7",
		"name":"2nd task here"
	}]
}

Update a document

Update a repository document.

HTTP request:

PUT /db/{repository-name}/{doc-id}

Format: JSON

Body:

The JSON of fields you want updated only. No need to pass back the entire document.

Note that the development server will replace a document and not just update the fields.

Example:

curl -H "Content-Type: application/json" \
     -H "SB-PUBLIC-KEY: your-pub-key" \
     -H "Authorization: Bearer user-token" \
     -X PUT
     -d '{"done": false, "assignedTo": "dominic"}'
     https://na1.staticbackend.com/db/tasks/5e185bdcb1374eaf8b994bf7

Note that you may add new field when updating a document.

Response:

true

Delete documents

Delete a repository document.

HTTP request

DELETE /db/{repository-name}/{doc-id}

Example:

curl -H "Content-Type: application/json" \
     -H "SB-PUBLIC-KEY: your-pub-key" \
     -H "Authorization: Bearer user-token" \
     -X DELETE
     https://na1.staticbackend.com/db/tasks/5e185bdcb1374eaf8b994bf7

Response:

1

Returns the number of document deleted.

Focus Centric inc. terms of service | privacy policy