npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-odata-server-ex

v0.0.4

Published

OData server with adapter for mongodb and nedb,another one just change method patch to put

Downloads

3

Readme

#Node simple OData server NPM Version License Build Status

Super simple implementation of OData server running on Node.js with easy adapters for mongodb and nedb. Just define an OData model, provide a mongo or nedb database, hook into node.js http server and run.

It supports basic operations you would expect like providing $metadata, filtering and also operations for insert, update and delete. On the other hand it suppose to be really simple so you don't get support for entity links, batch operations, atom feeds and many others.

The implementation is tested with .net OData client and it should fulfill basic protocol requirements.

##Get started

This is how you can create an OData server with node.js http module and nedb.

var http = require('http');
var Datastore = require('nedb');
var db = new Datastore( { inMemoryOnly: true });
var ODataServer = require("simple-odata-server");

var model = {
    namespace: "jsreport",
    entityTypes: {
        "UserType": {
            "_id": {"type": "Edm.String", key: true},
            "test": {"type": "Edm.String"},            
        }
    },   
    entitySets: {
        "users": {
            entityType: "jsreport.UserType"
        }
    }
};

var odataServer = ODataServer("http://localhost:1337")
    .model(model)
    .onNeDB(function(es, cb) { cb(null, db)});


http.createServer(odataServer.handle.bind(odataServer)).listen(1337);

Now you can try requests like: GET http://localhost:1337/$metadata GET http://localhost:1337/users?$filter=test eq 'a' or test eq 'b'&$skip=1&$take=5 GET http://localhost:1337/users('aaaa') GET http://localhost:1337/users?$orderby=test desc GET http://localhost:1337/users/$count POST, PATCH, DELETE

##mongodb It works the same way with nedb and mongo. You just need to provide callback for mongo database instance.

MongoClient.connect(url, function(err, db) {
	odataServer.onMongo(function(cb) { cb(err, db); }); 
});

##express.js It works well also with the express.js. You even don't need to provide service uri in the ODataServer constructor because it is taken from the express.js request.

app.use("/odata", function (req, res) {
        odataServer.handle(req, res);
    });

##Configurations Using onNeDB and onMongo is just a simple way for initializing ODataServer. You can implement your own data layer or override default behavior using following methods:

odataServer
	.query(fn(setName, query, cb))
	.update(fn(setName, query, update, cb))
	.insert(fn(setName, doc, cb))
	.remove(fn(setName, query, cb))
	.beforeQuery(fn(setName, query, cb))
	.beforeUpdate(fn(setName, query, update))
	.beforeInsert(fn(setName, doc, cb))
	.beforeRemove(fn(setName, query, cb))
	.afterRead(fn(setName, result));
	//add hook to error which you can handle or pass to default
	.error(fn(req, res, error, default))

##Contributions I will maintain this repository for a while because I use it in jsreport. You are more than welcome to contribute with pull requests and add other basic operations you require.

##Limitations

  • document ids must have name _id
  • no entity links
  • no batch operations
  • no validations
  • ... this would be a very long list, so rather check yourself

##License See license