python - Flask-restless endpoints with user resolution and filtration -
how correctly should api returns objects belonging user asks them?
api/version/items/<items_id>
or
api/version/user/<user_id>/items/<items_id>
in first case, server queried database user id, obtains authentication.
i don't know how create both cases in flask-restless. think preprocessor useful, user_id authorization (jwt token), can't find way use search parameters db.
from flask_jwt import jwt, jwt_required, current_user ... manager.create_api(item, methods=['get'], collection_name='items', url_prefix='/api', preprocessors=dict(get_single=[api_auth],get_many=[api_auth])) @jwt_required() def api_auth(*args, **kwargs): user_id = current_user.id # code user id addition. pass
preprocessor place build query object. think endpoint items should like:
api/version/items
but whithin preprocessor build query object passed request:
get api/version/items?q={"filters":[{"name":"userid","op":"eq","val":10}]}