https://github.com/rmariuzzo/lowdb-api
⚡️ lowdb-api - Express middleware that serve a virtual RESTful API.
https://github.com/rmariuzzo/lowdb-api
development-environment lowdb restful-api
Last synced: 2 months ago
JSON representation
⚡️ lowdb-api - Express middleware that serve a virtual RESTful API.
- Host: GitHub
- URL: https://github.com/rmariuzzo/lowdb-api
- Owner: rmariuzzo
- License: mit
- Created: 2017-10-30T18:32:44.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2017-12-13T04:40:46.000Z (over 8 years ago)
- Last Synced: 2025-09-09T02:43:19.470Z (9 months ago)
- Topics: development-environment, lowdb, restful-api
- Language: JavaScript
- Homepage:
- Size: 37.1 KB
- Stars: 25
- Watchers: 3
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Features
- Support common http methods (get, post, put and delete).
- Custom API prefix.
- Relies on [lowdb](https://github.com/typicode/lowdb).
- Accept custom [lowdb adapter](https://github.com/typicode/lowdb#adapters-api).
## 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](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete). Unfortunately, I haven't found it... therefore, I created: [lowdb-api](https://github.com/rmariuzzo/lowdb-api).
## Installation
```
npm install lowdb-api
```
### Configuration
```js
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](https://github.com/typicode/lowdb#adapters-api).
### 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](https://github.com/rmariuzzo/lowdb-api/issues/new).
## Development
1. `yarn`
2. `yarn test` or `yarn test -- --watch`