New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-document-api

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-document-api

HTTP API endpoint/middleware for `node-document` ODM for Node.js.

latest
Source
npmnpm
Version
0.1.0-pre1
Version published
Maintainers
1
Created
Source

NODE-DOCUMENT-API preview Build Status

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

Keywords

document

FAQs

Package last updated on 13 May 2013

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