npm.io
3.0.0 • Published yesterday

tingo-rest

Licence
MIT
Version
3.0.0
Deps
2
Size
8 kB
Vulns
0
Weekly
0
Stars
1

Tingo Rest

Minimal Express middleware exposing a JSON CRUD API over TingoDB

Usage

npm install tingo-rest

Create an index.js:

import express from 'express';
import tingoRest from 'tingo-rest';

const app = express();
app.use('/api', tingoRest('data'));

app.listen(3000);

API

The middleware is mounted under a base path (/api above). Each <resource> maps to a TingoDB collection file inside the data directory, created on demand.

Method Path Description
GET /api/<resource> List all documents
GET /api/<resource>?<field>=<value> List documents matching all given filters
GET /api/<resource>/<id> Get one document, 404 if missing
POST /api/<resource> Insert a JSON object, responds 201 with a Location header
PUT /api/<resource>/<id> Replace a document, 404 if missing
PATCH /api/<resource>/<id> Partially update a document ($set), 404 if missing
DELETE /api/<resource>/<id> Remove a document and return it, 404 if missing

Notes:

  • Documents get an auto-generated numeric id; TingoDB's internal _id is never exposed.
  • Client-supplied id/_id properties are ignored on writes.
  • Unknown routes respond 404, errors respond JSON { "error": "..." }.
  • The data directory is created automatically if missing.

Filtering

Every query parameter is treated as an equality filter; multiple parameters are AND-combined. Repeating a parameter matches any of its values.

GET /api/users?city=Cottbus&acc=micha
GET /api/users?acc=micha&acc=tom

A <field>_like parameter matches case-insensitive substrings instead of exact values. Regular expression characters in the value are treated literally.

GET /api/users?email_like=%28micha

Keywords