This is just a toy module for creating a REST interface to MongoDB which uses jsonschema
to validate data before trying to save into MongoDB collection.
This example creates a REST server with the following routes:
GET
/users/<string:id>
- return a single document fromusers
as JSON or204
PUT
/users/<string:id>
-PUT
a JSON document intousers
or400
if data does not validate with the schemaGET
/users
- get all documents fromusers
as JSON
from mongorest import Server
app = Server('test', host='my.db.server', port=27017)
users_schema = {'type': 'object',
'properties': {
'name': {'type': 'string'},
'age': {'type': 'number',
'minimum': 0},
'admin': {'type': 'boolean'}},
'required': ['name', 'age', 'admin']}
app.register_collection('users', users_schema)
app.run()