lowdb-api
v1.0.3
Published
lowdb-api is an Express middleware that interpret all requests as a real RESTful API.
Downloads
5
Maintainers
Readme
Features
- Support common http methods (get, post, put and delete).
- Custom API prefix.
- Relies on lowdb.
- Accept custom lowdb adapter.
Motivation
During initial development process, I usually want to interact with an API, but I don't want to spend time writing one. I was looking for a catch-all RESTful endpoint where I could do commons CRUD operations. Unfortunately, I haven't found it... therefore, I created: lowdb-api.
Installation
npm install lowdb-api
Configuration
const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
const lowdbApi = require('lowdb-api')
const app = express()
const file = path.join(__dirname, './db.json')
const options = {}
app.use(bodyParser.json())
app.use(lowdbApi(file, options))
Options
prefix
- (string, default: null) specify the prefix if you want to mount lowdb-api under a path (example: /api/v1)adapter
- (string, default: lowdb/adapters/FileSync) a lowdb adapter.
Usage
For the aforementioned configuration the following paths will be interpreted:
GET: /resources
- list all resources.GET: /resources/:id
- get a resource by its id.POST: /resources
- create a new resource in the list.PUT: /resources/:id
- update an existing resource.DELETE: /resources/:id
- delete an existing resource.
Issues
If you spot a bug please create an issue.
Development
yarn
yarn test
oryarn test -- --watch