Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mkuprionis
Created July 21, 2012 09:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkuprionis/3155322 to your computer and use it in GitHub Desktop.
Save mkuprionis/3155322 to your computer and use it in GitHub Desktop.
Flask-Restless with URL rules example
# flask-restless.views.API
class API(ModelView):
def get(self, instid, **kwargs):
<...>
self._search(**kwargs)
<...>
def _search(self, **kwargs):
<...>
self._before_search(data, **kwargs)
<...>
# Extending class
class ItemAPI(API):
def _before_search(data, user_id, **kwargs):
data['filters'].append({
'name': 'owner_id',
'op': 'equals',
'val': user_id
})
return True
# Actual API
manager.create_api(
Item,
methods=['GET', 'POST', 'PUT', 'DELETE'],
api_class=ItemAPI,
collection_name='/user/<int:user_id>/items')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment