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.
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.
- Flask
- pymongo
- (optional) MongoKit (when using the mongokit validation)
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)
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.
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.