GithubHelp home page GithubHelp logo

rest-flat-file-db's Introduction

rest-flat-file-db

Build Status dependencies devDependencies styled with prettier FOSSA Status

REST API for flat-file-db powered by koa2

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

// 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

FOSSA Status

rest-flat-file-db's People

Contributors

balazs4 avatar fossabot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

fossabot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.