https://github.com/balazs4/rest-flat-file-db
flat-file-db + REST = rest-flat-file-db
https://github.com/balazs4/rest-flat-file-db
database db flat-file-db lightweight rest-api
Last synced: about 1 month ago
JSON representation
flat-file-db + REST = rest-flat-file-db
- Host: GitHub
- URL: https://github.com/balazs4/rest-flat-file-db
- Owner: balazs4
- Created: 2017-05-07T17:39:24.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-11T09:31:41.000Z (over 8 years ago)
- Last Synced: 2025-07-09T13:35:29.105Z (12 months ago)
- Topics: database, db, flat-file-db, lightweight, rest-api
- Language: JavaScript
- Homepage:
- Size: 58.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rest-flat-file-db
[](https://travis-ci.org/balazs4/rest-flat-file-db)
[](https://david-dm.org/balazs4/rest-flat-file-db)
[](https://david-dm.org/balazs4/rest-flat-file-db?type=dev)
[](https://github.com/prettier/prettier)
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fbalazs4%2Frest-flat-file-db?ref=badge_shield)
> REST API for [flat-file-db](https://github.com/mafintosh/flat-file-db) powered by [koa2](https://github.com/koajs/koa)
## About
This is a tiny module which extends the lightweight `flat-file-db` key-value based `to-go` datastorage.
It might be useful for small projects (e.g. hackathon).
## Usage
### As standalone instance
```
# install the module globally
$ npm install -g rest-flat-file-db
# start the module with default parameters
$ rest-flat
# OR start it with custom parameters
$ PORT=3333 DB=/tmp/mydatabase rest-flat
```
### As module
`$ npm install rest-flat-file-db --save`
```javascript
// index.js
const restflat = require('rest-flat-file-db');
const flatdb = require('flat-file-db');
const app = restflat(flatdb.sync('/tmp/mydatabase'));
// this is just a normal koa2 app and it is ready to launch.
app.listen();
```
**Hint**: You can pass your own `koa` app as well if you want to make some setup on it before the rest-flat endpoints will be initialized. (e.g. Authentication)
This second parameter is optional. In default case the `koa` instance will be created by the `rest-flat-file-db` itself.
## REST API
#### GET /
200 and a single object contains all key-value pairs of the database
#### GET /:key
200 (if the `key` could be found, otherwise 404) and the value of :key
#### POST /:key
409 if `key` already exists in the database otherwise 201 and the body of the post will be stored with the `key` in the db (response.headers['location'] contains the url to the item)
#### PUT /:key
200 (if the `key` could be found, otherwise 404) and the **updated** item with its new content
#### PATCH /:key
200 (if the `key` could be found, otherwise 404) and the **merged** (with `Object.assign` call) item with its new content
#### DELETE /:key
200 (if the `key` could be found, otherwise 404) and the **deleted** item from the db (it acts like a `pop` call on a stack)
#### POST /
201 and the body of the post will be stored with a **generated** key in the db (response.headers['location'] contains the url to the item)
## License
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fbalazs4%2Frest-flat-file-db?ref=badge_large)