Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider URL structure for passing query data from frontend #7

Closed
ctgraham opened this issue Jul 23, 2021 · 1 comment
Closed

Consider URL structure for passing query data from frontend #7

ctgraham opened this issue Jul 23, 2021 · 1 comment

Comments

@ctgraham
Copy link
Member

The Multiple Village Download URL is currently structured to concatenate the villages and the topic with underscores as a GET request.

For example:
http://backend.tld/advancesearch/download/1_3_2_economy

Here 1, 2, and 3 are village ids and economy is the topic.

This does not align well with REST principles as it combines different query terms (objects) together.

This might be better represented as:
http://backend.tld/advancesearch/download/1_3_2/economy
or
http://backend.tld/advancesearch/download/1,3,2/economy
or
http://backend.tld/advancesearch/download/?village=1,3,2&term=economy

It might be tempting to pass query data via POST, so that you can hand of a JSON object directly, like:

{
  "village": [1, 2, 3],
  "term": "economy"
}

But a POST request should represent a data-change event, and this limits the ability for effective caching because the query context is removed from the URI.

@ctgraham
Copy link
Member Author

Converted to querystring here:

@village_blueprint.route("/download/", methods=["GET"], strict_slashes=False)
def downloadData():
dir_path = os.getcwd()
single_dir = os.path.join(dir_path,"app_func","single_csv")
# print("path is",os.path.join(single_dir, path))
village_id = request.args.get("village")
topic = request.args.get("topic", None)
path = village_id+"_"+topic
if os.path.exists(os.path.join(single_dir, path)):
return send_from_directory(single_dir, path, as_attachment=True)
return jsonify({"code":4003,"message":"File is not exist or file can't download"})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant