Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gevious/flask_slither

A small library to interface between a mongodb and JSON RESTful API endpoints.
https://github.com/gevious/flask_slither

Last synced: 11 days ago
JSON representation

A small library to interface between a mongodb and JSON RESTful API endpoints.

Awesome Lists containing this project

README

        

Flask Slither
=============

[![Build Status](https://travis-ci.org/gevious/flask_slither.png?branch=master)](https://travis-ci.org/gevious/flask_slither)
[![Build Coverage](https://coveralls.io/repos/gevious/flask_slither/badge.png?branch=master)](https://coveralls.io/r/gevious/flask_slither)

A small library to interface between a mongodb and JSON RESTful API resources.
It uses Flask's `MethodView` and populates it with boilerplate code. It is based
on django tastypie.

The idea behind Slither
=======================
MongoDB, or any document database, already has JSON payloads in the required
format. Not a lot of work needs to be done in de-normalising the data and
building a JSON payload. Slither aims to be the small layer between the
database and the API resource. It is there to do some housekeeping, but not to
get in the way.

The aim is to be fully compatible with the [JSONApi](http://jsonapi.org/) spec as
well as comply to the highest RESTful standards (including HATEOAS) as much as possible.

Needed Libraries
================
* Flask
* pymongo
* (optional) MongoKit (when using the mongokit validation)

Usage
=====
Here are the basic code snippets you need to use to get up and running:

from flask.ext.slither import register_api
from flask.ext.slither.resources import BaseResource

class UserResource(BaseResource):
def __init__(self, *args, **kwargs):
self.collection = 'users' # The db collection name

register_api(app, UserAPI)

Defaults
========
By default no authentication, authorization and validation is done on any
requests. These can be added easily by including them from slither or
by writing your own class and using it with your resource.

Custom Resources
================
If having basic GET, POST, PATCH, PUT, DELETE endpoints isn't sufficient, you
can add new endpoints in the usual flask way by adding a new definition with
the @route decorator. At this stage, however, you'll also need to add the
plumbing.