Skip to content

gevious/flask_slither

Repository files navigation

Flask Slither

Build Status Build Coverage

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 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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages