Created
September 23, 2013 00:09
-
-
Save tlmaloney/6665103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SERVER_NAME = '127.0.0.1:5000' | |
# Let's just use the local mongod instance. Edit as needed. | |
# Please note that MONGO_HOST and MONGO_PORT could very well be left | |
# out as they already default to a bare bones local 'mongod' instance. | |
MONGO_HOST = 'localhost' | |
MONGO_PORT = 27017 | |
#MONGO_USERNAME = 'user' | |
#MONGO_PASSWORD = 'user' | |
MONGO_DBNAME = 'apitest' | |
# Enble reads (GET), inserts (POST) and DELETE for resources/collections | |
# (if you omit this line, the API will default to ['GET'] and provide | |
# read-only access to the endpoint). | |
RESOURCE_METHODS = ['GET', 'POST', 'DELETE'] | |
# Enable reads (GET), edits (PATCH) and deletes of individual items | |
# (defaults to read-only item access). | |
ITEM_METHODS = ['GET', 'PATCH', 'DELETE'] | |
schema = { | |
# Schema definition, based on Cerberus grammar. Check the Cerberus project | |
# (https://github.com/nicolaiarocci/cerberus) for details. | |
'firstname': { | |
'type': 'string', | |
'minlength': 1, | |
'maxlength': 10, | |
}, | |
'lastname': { | |
'type': 'string', | |
'minlength': 1, | |
'maxlength': 15, | |
'required': True, | |
# talk about hard constraints! For the purpose of the demo | |
# 'lastname' is an API entry-point, so we need it to be unique. | |
'unique': True, | |
}, | |
# 'role' is a list, and can only contain values from 'allowed'. | |
'role': { | |
'type': 'list', | |
'allowed': ["author", "contributor", "copy"], | |
}, | |
# An embedded 'strongly-typed' dictionary. | |
'location': { | |
'type': 'dict', | |
'schema': { | |
'address': {'type': 'string'}, | |
'city': {'type': 'string'} | |
}, | |
}, | |
'born': { | |
'type': 'datetime', | |
}, | |
} | |
people = { | |
# 'title' tag used in item links. Defaults to the resource title minus | |
# the final, plural 's' (works fine in most cases but not for 'people') | |
'item_title': 'person', | |
# by default the standard item entry point is defined as | |
# '/people/<ObjectId>/'. We leave it untouched, and we also enable an | |
# additional read-only entry point. This way consumers can also perform | |
# GET requests at '/people/<lastname>/'. | |
'additional_lookup': { | |
'url': '[\w]+', | |
'field': 'lastname' | |
}, | |
# We choose to override global cache-control directives for this resource. | |
'cache_control': 'max-age=10,must-revalidate', | |
'cache_expires': 10, | |
# most global settings can be overridden at resource level | |
'resource_methods': ['GET', 'POST'], | |
'schema': schema | |
} | |
people_lastname = { | |
'source': 'people', | |
'resource_methods': ['GET', 'POST'], | |
'schema': schema, | |
} | |
DOMAIN = { | |
'people': people, | |
'people/lastname': people_lastname | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment