# Handle wayward paths by raising an API404Error @blueprint.route("/<path:invalid_path>", methods=["POST", "GET", "PUT", "DELETE", "PATCH", "HEAD"]) # leaving out methods should mean all, but tests haven't shown that behaviour. def missing_resource(invalid_path): docs_url = app.config.get("BASE_URL", "") + url_for('.docs') spec_url = app.config.get("BASE_URL", "") + url_for('.api_spec') raise Api404Error("No endpoint at {0}. See {1} for valid paths or read the documentation at {2}.".format(invalid_path, spec_url, docs_url)) @blueprint.route('/docs') def docs(): return render_template('api/v1/api_docs.html') @swag(swag_summary='Search your applications <span class="red">[Authenticated, not public]</span>', swag_spec=DiscoveryApi.get_application_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. @blueprint.route("/search/applications/<path:search_query>") @api_key_required def search_applications(search_query): # get the values for the 2 other bits of search info: the page number and the page size page = request.values.get("page", 1) psize = request.values.get("pageSize", 10) sort = request.values.get("sort") # check the page is an integer try: page = int(page) except: raise Api400Error("Page number was not an integer") # check the page size is an integer
# Handle wayward paths by raising an API404Error @blueprint.route("/<path:invalid_path>", methods=["POST", "GET", "PUT", "DELETE", "PATCH", "HEAD"]) # leaving out methods should mean all, but tests haven't shown that behaviour. def missing_resource(invalid_path): docs_url = app.config.get("BASE_URL", "") + url_for('.docs') spec_url = app.config.get("BASE_URL", "") + url_for('.api_spec') raise Api404Error("No endpoint at {0}. See {1} for valid paths or read the documentation at {2}.".format(invalid_path, spec_url, docs_url)) @blueprint.route('/docs') def docs(): return render_template('api/v1/api_docs.html') @swag(swag_summary='Search your applications <span class="red">[Authenticated, not public]</span>', swag_spec=DiscoveryApi.get_application_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. @blueprint.route("/search/applications/<path:search_query>") @api_key_required @analytics.sends_ga_event(GA_CATEGORY, GA_ACTIONS.get('search_applications', 'Search applications'), record_value_of_which_arg='search_query') def search_applications(search_query): # get the values for the 2 other bits of search info: the page number and the page size page = request.values.get("page", 1) psize = request.values.get("pageSize", 10) sort = request.values.get("sort") # check the page is an integer try: page = int(page) except: raise Api400Error("Page number was not an integer")
docs_url = app.config.get("BASE_URL", "") + url_for('.docs') spec_url = app.config.get("BASE_URL", "") + url_for('.api_spec') raise Api404Error( "No endpoint at {0}. See {1} for valid paths or read the documentation at {2}." .format(invalid_path, spec_url, docs_url)) @blueprint.route('/docs') def docs(): return render_template('api/v1/api_docs.html') @swag( swag_summary= 'Search your applications <span class="red">[Authenticated, not public]</span>', swag_spec=DiscoveryApi.get_application_swag() ) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. @blueprint.route("/search/applications/<path:search_query>") @api_key_required def search_applications(search_query): # get the values for the 2 other bits of search info: the page number and the page size page = request.values.get("page", 1) psize = request.values.get("pageSize", 10) sort = request.values.get("sort") # check the page is an integer try: page = int(page) except: raise Api400Error("Page number was not an integer")