Skip to main content

Flask restful API framework for MongoDB/MongoEngine

Project description

Flask-CuddlyRest
===============
A framework for manipulating mongoengine collections via a CUD-ly API

It has taken inspiration from:
- https://github.com/brettlangdon/mongorest
- https://github.com/elasticsales/flask-mongorest

All credit goes to those projects! :)

[![Build Status](https://travis-ci.org/wuurrd/Flask-CuddlyRest.png)](https://travis-ci.org/wuurrd/Flask-CuddlyRest)

Setup
=====

``` python
from flask import Flask
from flask.ext.mongoengine import MongoEngine
from flask.ext.cuddlyrest import CuddlyRest
from flask.ext.cuddlyrest.views import Resource


app = Flask(__name__)

app.config.update(
MONGODB_HOST = 'localhost',
MONGODB_PORT = '27017',
MONGODB_DB = 'mongorest_example_app',
)

db = MongoEngine(app)
api = CuddlyRest(app)

class User(db.Document):
email = db.EmailField(unique=True, required=True)

class Content(db.EmbeddedDocument):
text = db.StringField()

class Post(db.Document):
title = db.StringField(max_length=120, required=True)
author = db.ReferenceField(User)
content = db.EmbeddedDocumentField(Content)

api.register(Post, '/posts')
```

With this app, following cURL commands could be used:
```
Create a Post:
curl -H "Content-Type: application/json" -X POST -d \
'{"title": "First post!", "author_id": "author_id_from_a_previous_api_call", "content": {"text": "this is our test post content"}}' http://0.0.0.0:5000/posts/
{
"id": "1",
"title": "First post!",
"author": "author_id_from_a_previous_api_call",
"content": {
"text": "this is our test post content"
}
}
```
Get a Post:
```
curl http://0.0.0.0:5000/posts/1/
{
"id": "1",
"title": "First post!",
"author_id": "author_id_from_a_previous_api_call",
"content": {
"text": "this is our test post content"
}
}
```
List all Posts or filter by the title:
```
curl http://0.0.0.0:5000/posts/ or curl http://0.0.0.0:5000/posts/?title__startswith=First%20post
{
"data": [
{
"id": "1",
"title": "First post!",
"author_id": "author_id_from_a_previous_api_call",
"content": {
"text": "this is our test post content"
}
},
... other posts
]
}
```
Delete a Post:
```
curl -X DELETE http://0.0.0.0:5000/posts/1/
```

Request Params
==============

**skip** and **limit** => utilize the built-in functions of mongodb.
**order_by** => order results if this string is present in the Resource.allowed_ordering list.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-CuddlyRest, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size Flask-CuddlyRest-0.1.3.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page