kul

Kule

🍋REST interface for MongoDB.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

491

Maintenance

Last Commit

3yrs ago

Contributors

5

Package

Dependencies

0

License

UNKNOWN

Categories

Readme

Simple REST Interface for MongoDB.

Kule is a REST interface for MongoDB. You can use kule as a temporary backend for your backend needed apps.

Requirements

  • Bottle
  • Pymongo

Installation

pip install kule

Usage

python -m kule --database foo --collections users,documents

That's all.

Kule

Now you can interact with your API.

MethodPathAction
GET/usersReturns all records. You can give limit and offset parameters to paginate records.
GET/users/:idReturns a single document
POST/usersCreates a new document
PUT/users/:idReplaces an existing document
PATCH/users/:idUpdates a document
DELETE/users/:idRemoves an existing document

Customization

You can customize your API response for your requirements. For example, you can provide authentication method.

Example

You can override an existing endpoint.

from kule import Kule

class MyKule(Kule):
    def delete_detail(self, collection, pk):
        return self.not_implemented()

Magical method names ...

You can override specific endpoint with kule's magical methods.

from kule import Kule

class MyKule(Kule):
    def get_users_list(self, collection):
        return ["merhaba", "hello", "hola"]

Building custom bundle

Also there is a way to build customized bundles.

from kule import Kule

class MyKule(Kule):
    def build_users_bundle(self, user):
        first_name, last_name = user.get("full_name").split()
        return {"first_name": first_name, 
                "last_name": last_name}

Starting app

mykule = MyKule(database="foo")
mykule.run()

Using with Backbone.js

You have to override the parse method of collections. Because models listing on objects key.

Backbone.Collection.prototype.parse = function(data) {
    return data.objects ? data.objects : data;
};

// examples
var Document = Backbone.Model.extend({
    urlRoot: "http://localhost:8000/documents", // Supports CORS
    idAttribute: "_id"
});
var Documents = Backbone.Collection.extend({
    model: Document,
    url: "http://localhost:8000/documents"
});

// lets play
var _document = new Document({"title": "hello"});
_document.save()

_document.on('reset', function () {
    console.log(_document.id);
})

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100