def get_api(api, cors_handler, marshal=None, resp_model=None, parser=None, json_resp=True): """Returns default API decorator for GET request. :param api: Flask rest_plus API :param cors_handler: CORS handler :param marshal: The API marshaller, e.g. api.marshal_list_with :param resp_model: The API response model """ funcs = [ cors_handler, no_cache, log_header(), ] if json_resp: funcs.append(as_json) funcs.append( api.doc(responses={ 403: 'Not Authorized', 404: 'Resource does not exist', }), ) if parser: funcs.insert(-1, api.doc(parser=parser)) if marshal and resp_model: funcs.insert(-1, marshal(resp_model)) return utils.compose(*funcs)
def _common_api(api, cors_handler, marshal=None, req_model=None, resp_model=None, parser=None): """Returns default API decorator for common r/w requests. :param api: Flask rest_plus API :param cors_handler: CORS handler :param marshal: The API marshaller, e.g. api.marshal_list_with, this will override the default `api.marshal_with()` :param req_model: The API request model :param resp_model: The API response model """ funcs = [ cors_handler, no_cache, log_header(), as_json, api.doc(responses={ 403: 'Not Authorized', 404: 'Resource does not exist', }), ] if parser or req_model: params = dict() if parser: params['parser'] = parser if req_model: params['body'] = req_model funcs.insert(-1, api.doc(**params)) if marshal and resp_model: funcs.insert(-1, marshal(resp_model)) elif resp_model: funcs.insert(-1, api.marshal_with(resp_model)) return utils.compose(*funcs)