aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-08-26 12:35:52 +0300
committerBonfaceKilz2024-08-26 15:35:33 +0300
commit5d0b1033f6f75e7a67226a57762e7a5c73d722a2 (patch)
tree10194a8405d1881a8ad3d8082d6b7a1c595a3c7f
parentae4bca95b9923be642b3b1f6f7771b7ffce6ed5f (diff)
downloadgenenetwork3-5d0b1033f6f75e7a67226a57762e7a5c73d722a2.tar.gz
Set correct content-header & status code for ld+json/json response.
* gn3/api/metadata.py: Import jsonify, make_response. (get_wiki_entries): Set a 404 status code when a response is empty. Set correct Content-Type header for ld+json. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn3/api/metadata.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index d8f16f9..02fb721 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -7,6 +7,8 @@ from pathlib import Path
from authlib.jose import jwt
from flask import Blueprint
+from flask import jsonify
+from flask import make_response
from flask import request
from flask import current_app
@@ -398,9 +400,18 @@ CONSTRUCT {
@metadata.route("/wiki/<symbol>", methods=["GET"])
def get_wiki_entries(symbol):
"""Fetch wiki entries"""
- return get_wiki_entries_by_symbol(
+ content_type = request.headers.get("Content-Type")
+ status_code = 200
+ response = get_wiki_entries_by_symbol(
symbol=symbol,
sparql_uri=current_app.config.get("SPARQL_ENDPOINT"))
+ if not response.get("data"):
+ status_code = 404
+ if content_type == "application/ld+json":
+ response = make_response(response)
+ response.headers["Content-Type"] = "application/ld+json"
+ return response, status_code
+ return jsonify(response.get("data")), status_code
@metadata.route("/genewikis/ncbi/<symbol>", methods=["GET"])