🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

json_api

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json_api

Simple JSON REST API for NeDB (or MongoDB)

0.0.3
latest
npm
Version published
Weekly downloads
1
-90%
Maintainers
1
Weekly downloads
 
Created
Source

JSON API

A simple middleware for mounting a RESTful JSON API

Usage

Add as a middleware

var Datastore = require('nedb');
var store     = new Datastore({ filename: "path/to/file", autoload: true });
var json_api  = require("json_api");

app.use("/path/to/mount/to", json_api(store));

create a record:

curl -4 -X POST -H "Content-Type: application/json" -d '{"name":"curl"}' http://localhost:8025/path/to/mount/to

get a record:

curl -4 -X GET -H "Content-Type: application/json" http://localhost:8025/path/to/mount/to/<resource-id>

I have only tested with NeDB but should also work with MongoDB

Check out the tests to see more usage examples.

Testing

npm install -g mocha
mocha

Similar Projects

  • loopback-connector-rest

Why?

If you read this article from StrongLoop about comparing different libraries for building RESTful APIs

I would add this with the following entry:

var app   = require("express")();
var Store = require("nedb")
var store = new Store({ filename: "data/items.db", autoload: true });

app.use(require('body-parser').json())
   .use("/items", require("json_api")(store));

app.listen(8025);

Pros

  • Very quick RESTful API development
  • Just a simple middleware to inject into your existing workflow
  • Great for prototyping
  • No learning curve
  • Very lightweight (can read entire source in a few minutes)

Cons

  • Only built with NeDB/MongoDB in mind
  • Only inteded for trivial apps, prototypes or stubs

FAQs

Package last updated on 28 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts