Skip to main content
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
- https://github.com/mozilla-services/cornice (for sphinx integration)

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.

Sphinx doc generation
=====================

There are facilities to generate sphinx documentation that document the REST
APIs as handled by Flask-CuddlyREST.

Setup
-----

Edit `conf.py` and add the following:

```
import flask_cuddlyrest
```

Make sure `flask_cuddlyrest.ext.sphinxext` is added to the list of extensions, for instance:
```
extensions = ['sphinx.ext.autodoc',
'flask_cuddlyrest.ext.sphinxext']
```

Usage
-----

To add a description of the operations that Flask-CuddlyREST handles:

```
.. cuddlyrest::
:document: Sock # The name of the class where the mongo document
binding is defined.
:url: /socks # the url on which the document object is served.
```

To add a description of the JSON objects Flask-CuddlyREST handles:

```
.. cuddlyobject::
:module: the.module.in.which.the.document.is.defined
:document: Sock # The name of the class where the mongo document
binding is defined.
:id: sock_class # the named hyperlink reference id which the
rest of the API doc can use to reference this generated
documentation block. This is optional: when not provided, the
default value will be set to the document name, lower cased.

```

Metadata

Release files for Flask-CuddlyRest 0.1.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-CuddlyRest 0.1.15
File Size Uploaded Provenance Actions
Flask-CuddlyRest-0.1.15.tar.gz 11.1 kB Without provenance Details for Flask-CuddlyRest-0.1.15.tar.gz

Release files / Flask-CuddlyRest-0.1.15.tar.gz

Download URL Flask-CuddlyRest-0.1.15.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b7da20a407defe257c08c336e23b49476f1056ef534fa46f66446dc744478b09
BLAKE2b-256 checksum
How to use checksums
158c436acabbde7c7e202d77a957ea2ca41f875975b9981c4e7c1747f147b2e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for Flask-CuddlyRest 0.1.15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page