0.1.3 • Published 8 years ago

expose-data v0.1.3

Weekly downloads
10
License
-
Repository
github
Last release
8 years ago

ExposeJs

The goal of the project is to provide a flexible and configurable mechanism for building simple services that can be exposed over HTTP.

The first exporter implemented is based on mongoose models. This takes your schemas and front-ends them with HTTP, allowing you full CRUD capability over your entities, to include managing associations.

Installation

$ npm install expose-data --save

Usage

1. create a config file under the name apiconfig.js

This file must contains :

  1. Database url.

  2. Array of models to expose.

  3. Each model has a name, a schema and list of possible actions.

Example of apiconfig.js
module.exports = { 
        dbUrl: "mongodb://user:pass@localhost:27017/library",
        models: [{
            name: "book",
            scheme: {
                title: { type: String },
                author: { type: String },
                genre: { type: String }
            },
            ops: ["findAll", "findById", "insert"]
        }]
};

2. create the app

The file that launch the app must be in the root folder of the project.

The app is easly created through a single line:

require('expose-data').listen(3000)

3. access it

  • The entry point for findAll is /theModelName/ for example localhost:3000/book/ returns the folowing response
[
  {
    "_id": "58af6174734d1d48176ad224",
    "title": "title",
    "author": "author",
    "genre": "genre",
    "links": {
      "self": "http://localhost:3000/book/58af6174734d1d48176ad224"
    }
  }
]
  • The CRUD operations are avaibible through the different http verbs on the URI /theModelName/:id

Upcoming features

  • Custom queries
  • security config

Contributing

  1. Fork it!
  2. Submit a pull request
  3. Suggest features

License

MIT