Restdb Cheat Sheet
Restdb Cheat Sheet
2)
To make life easier for restdb.io developers, we have assembled a compact version of our docs for
reference. Here you'll find reference to the Collection API, the Media Content API, the Meta data API, Mail
API, Authentication API and the Codehook APIs.
Database REST API URLs are prefixed with the full database name.
https://{db-name}.restdb.io/rest/{collection}[.<format>]?q={}&h={}&...
For example, a query against the customer collection in the database mydb-fex0:
https://mydb-fex0.restdb.io/rest/customers?q={"name": "Jane"}
1/9
Operation Resource Description
Parameter Description
Query hints to specify: fields, max, skip and orderby. Aggregation parameters can also be
specified as hints, read more here :
h
/rest/people?q={}&h={"$fields":
{"title":1},"$max":10,"$skip":5,"$orderby":{"body":1}}
Specifies which field(s) should be used to sort the result. You can add multiple fields by
sort simply adding another sort parameter. Default sort=_id:
/rest/people?q={}&sort=lastname
Sort direction. Allowed values are 1 (ascending) and -1 (descending). Used together with
dir sort. Multiple dir parameters can be used in conjunction with sort:
/rest/people?q={}&sort=lastname&dir=-1
2/9
Parameter Description
Returns an object with both data and total count. Totals equals to max parameter or
default 1000:
totals
Output from query /rest/people?totals=true returns the object {data: [ … ],
totals: { total: 100, count: 40, skip: 0, max: 1000}}
Perform aggregation function on data groups. Useful together with groupby parameter.
Avaliable functions; SUM, AVG, MIN, MAX and COUNT Docs:
aggregate
/rest/people?
groupby=gender&aggregate=SUM:weight&aggregate=AVG:age
Output format from request. .html returns a standard markup for all fields. .js (Javascript)
returns a script that can be included in a web page for search engine indexing. .json
format
standard JSON format:
/rest/people.html
Return all items that refers to a record. Requires a record _id in the query or path:
referencedby
/rest/people/56011150e1321c7300000001?referencedby=true
Replace media ID's with a full record from the media archive:
fetchmediadata
/rest/people?fetchmediadata=true
3/9
Function Format Comment Example
$groupby:
Groupby Returns "groupkey":[array] h={"$groupby":["category"]}
["field", ...]
Groupby
$groupby: Format strings for: ss, hh,
(dates h={"$groupby":
["$DATE:format", mm, dd, MM, YY. All
with ["$DATE.MMM:registered"]}
...] formats at momentjs.com
formats)
h={"$groupby":["category"],
Grand $aggregate- Recursive aggregation
"$aggregate": ["AVG:score"],
totals grand-total: true functions of groups
"$aggregate-grand-total": true}
Get binary data for media object with ID. ID is a valid ObjectID for an
object in the media archive or an existing filename. Parameter s options;
GET /media/ID ?s=t (thumbnail), ?s=w (web) and ?s=o (original size). No API-key
required. Use parameter ?download=true if you want the image or
file to be downloaded instead of displayed.
GET /media/ID/meta Get JSON structure with media object metadata. Requires API-key.
GET /rest/_meta Get meta data for the database as a JSON object.
4/9
Operation Resource Description
GET /rest/{collection}/_meta Get meta data for the collection as a JSON object.
Mail API
Operation Resource Description
Authentication API
Operation Resource Description
Generate a new JWT token. Body must contain a path to a secret and a
POST /auth/jwt payloan with JWT claims, e.g {"secret": "path from global
settings", "payload": {"email": "[email protected]"}}
GET /auth/userinfo Get data about a user. Returns email, displayname and image.
Logout a user, invalidates the login token. This token can no longer be
POST /auth/logout
used for API access.
Codehook API
Database operation hooks
beforeDELETE(req,
req.body, res.end([optional error]) before a DELETE
res)
5/9
Codehook Available parameters Description
triggers on a crontab
runJob(req, res) res.end("Optional message to log")
expression
request(options,
options: json, callback(error, response, body) Network API
callback)
Variable list of
arguments log.info,
log.debug(str, ...) Writes output to Rest inspector
log. debug, log. error,
log.fatal
6/9
Function Parameters Description
Run Handlebars on
template(str, context) str with context json Handlebars templating function
data
Run Markdown
markdown(str) Returns valid HTML
parser on str
auth.decode_jwt(token,
A valid JWT token callback with (err, decodedjwt) as arguments
callback)
token-string, secret-
verifyHash(token, secret, Verify crypto tokens, e.g. Shopify webhook
string, algorithm,
'RSA-SHA256', 'base64'); token
encoding
Server Pages
Use these Handlebars helper tags inside RestDB Pages.
Run database queries and bind data to the Page view context.
{#context}
{
"mydata": {
"collection": "contacts",
{{#context}} "query": {"name": "jane"},
"hints": {"$orderby": {"name": 1}}
}
}
{/context}
...
7/9
Helper tag Description
Logic statement.
{{#ifcond val1 '==' val2}}
{{val1}} is equal to {{val2}}.
{{#ifCond}}
{{else}}
{{val1}} and {{val2}} are not equal.
{{/ifcond}}
8/9
Helper tag Description
Page Codehooks, serverless Javascript functions. Bind output from function to Page
context.
{(#codehook}} {{#codehook code="aPageCodeHook.js"}}
Inside scope of codehook with {{field}} set by script.
{{/codehook}}
restdb.io is a fast and simple NoSQL cloud database service. With restdb.io you get schema, relations,
REST API and an efficient multi-user admin UI for working with data. Our customers use it for backends,
business databases, API-first CMS, data collection and much more. It is easy to get started with the free
development plan.
9/9