node-document-api
v0.1.0-pre1
Published
HTTP API endpoint/middleware for `node-document` ODM for Node.js.
Downloads
2
Readme
NODE-DOCUMENT-API preview
HTTP API endpoint/middleware for node-document ODM for Node.js.
About
Unified HTTP API for write/read data to/from differen kinds of storages/databases.
HTTP API
POST
(:route)/:type/:id
HTTP POST /post/1 { "title": "Post 1", "description": "Lorem ipsum..." }
/* 200 OK */ [ { "_type": "post", "_id": 1, "title": "Post 1", "description": "Lorem ipsum..." } ]
(:route)/:type/:id,...,:id
HTTP POST /post/1,2,3 [ { "title": "Post 1", "description": "Lorem ipsum..." }, { "title": "Post 2", "description": "Lorem ipsum..." }, { "title": "Post 3", "description": "Lorem ipsum..." } ]
/* 200 OK */ [ true, true, true ]
PUT
(:route)/:type/:id
HTTP PUT /post/1 { "title": "Post 1", "description": "Lorem ipsum...", "extra": true }
/* 200 OK */ [ { "_type": "post", "_id": 1, "title": "Post 1", "description": "Lorem ipsum...", "extra": true } ]
(:route)/:type/:id,...,:id
HTTP PUT /post/1,2,3 [ { "title": "Post 1", "description": "Lorem ipsum...", "extra": true }, { "title": "Post 2", "description": "Lorem ipsum...", "extra": true }, { "title": "Post 3", "description": "Lorem ipsum...", "extra": true } ]
/* 200 OK */ [ true, true, true ]
GET
(:route)/:type/:id
HTTP GET /post/1
/* 200 OK */ [ { "_type": "post", "_id": 1, "title": "Post 1", "description": "Lorem ipsum..." } ]
(:route)/:type/:id,...,:id
HTTP GET /post/1,2,3
/* 200 OK */ [ { "_type": "post", "_id": 1, "title": "Post 1", "description": "Lorem ipsum..." }, { "_type": "post", "_id": 2, "title": "Post 2", "description": "Lorem ipsum..." }, { "_type": "post", "_id": 3, "title": "Post 3", "description": "Lorem ipsum..." } ]
DELETE
(:route)/:type/:id
HTTP DELETE /post/1
/* 200 OK */ [ { "_type": "post", "_id": 1, "title": "Post 1", "description": "Lorem ipsum..." } ]
(:route)/:type/:id,...,:id
HTTP DELETE /post/1,2,3
/* 200 OK */ [ false, true, true ]
Example
Using Connect.js:
var connect = require('connect')
var http = require('http');
var Document = require('node-document');
var API = require('node-document-api');
var Post = Document('Post');
Post.api = API({route: '/api'});
var app = connect();
app
.use(Post.api)
.use(function(req, res) {
res.end("Hello world!");
});
http.createServer(app).listen(3000, function() {
console.log('[node-document-api/examples/connect-example.js]: Listening on port %s', 3000);
});
Using Express.js:
var express = require('express')
var Document = require('node-document');
var API = require('node-document-api');
var Post = Document('Post');
Post.api = API({route: '/api'});
var app = express();
app
.use(Post.api)
.use(function(req, res) {
res.end("Hello world!");
});
app.listen(3000, function() {
console.log('[node-document-api/examples/express-example.js]: Listening on port %s', 3000);
});
Installation
$ npm install node-document-api
Test
Local tests:
$ make test
License
Released under the MIT license.
Copyright (c) Jonas Grimfelt