fatiherikli/kule

语言: Python

git: https://github.com/fatiherikli/kule

Kule是MongoDB的REST接口。
Kule is a REST interface for MongoDB.
README.md (中文)

MongoDB的简单REST接口。

Kule是MongoDB的REST接口。您可以将kule用作后端所需应用程序的临时后端。

要求

  • 瓶子
  • Pymongo

安装

pip install kule

用法

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

就这样。

Kule

现在,您可以与API进行交互。

Method Path Action
GET /users Returns all records. You can give limit and offset parameters to paginate records.
GET /users/:id Returns a single document
POST /users Creates a new document
PUT /users/:id Replaces an existing document
PATCH /users/:id Updates a document
DELETE /users/:id Removes an existing document

定制

您可以根据自己的要求自定义API响应。 例如,您可以提供身份验证方法。

您可以覆盖现有端点。

from kule import Kule

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

神奇的方法名称......

您可以使用kule的神奇方法覆盖特定端点。

from kule import Kule

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

构建自定义捆绑

还有一种方法可以构建自定义捆绑包。

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}

启动应用

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

与Backbone.js一起使用

您必须覆盖集合的解析方法。因为型号上市 对象键。

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);
})

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

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.

Method Path Action
GET /users Returns all records. You can give limit and offset parameters to paginate records.
GET /users/:id Returns a single document
POST /users Creates a new document
PUT /users/:id Replaces an existing document
PATCH /users/:id Updates a document
DELETE /users/:id Removes 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);
})