la
lowdb-api
npm i lowdb-api
la

lowdb-api

⚡️ lowdb-api - Express middleware that serve a virtual RESTful API.

by Rubens Mariuzzo

1.0.3 (see all)License:MITTypeScript:Not Found
npm i lowdb-api
Readme

lowdb api

lowdb-api is an Express middleware that interpret all requests as a real RESTful API.

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

  1. yarn
  2. yarn test or yarn test -- --watch

Downloads/wk

5

GitHub Stars

26

LAST COMMIT

5yrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

3

OPEN PRs

1
VersionTagPublished
1.0.3
latest
5yrs ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate