From 428f6eab3e9fbd177f0dc59857ba9ba9c87548a6 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Mon, 17 Jul 2023 12:18:12 +0200 Subject: refactoring --- gn3-guile/web/webserver.scm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gn3-guile/web/webserver.scm b/gn3-guile/web/webserver.scm index b6f3417..0803018 100755 --- a/gn3-guile/web/webserver.scm +++ b/gn3-guile/web/webserver.scm @@ -60,16 +60,13 @@ (,(mk-url "datasets")."Get a list of datasets"))))) -(define (sparql-scm query) - (json-string->scm - (bytevector->string (receive (response-status response-body) +(define (sparql-exec query) + "Execute raw SPARQL query returning a json object" + (bytevector->string (receive (response-status response-body) (http-request (string-append "https://sparql.genenetwork.org/sparql?default-graph-uri=&query=" (uri-encode query) "&format=application%2Fsparql-results%2Bjson")) response-body) "UTF-8" - ))) - -(define (sparql-exec query) - (sparql-scm query)) + )) (define (sparql-names response) (cdr (assoc "vars" (cdr (assoc "head" response)))) @@ -79,6 +76,13 @@ (cdr (assoc "bindings" (cdr (assoc "results" response ))))) +(define (sparql-scm query) + "Return dual S-exp" + (let response (((json-string->scm (sparql-exec query))) + (values (sparql-names response) (sparql-results response)) + ))) + + (define (sparql-exec query) "Return list of varnames and list of results" (let ([response (sparql-scm query)]) -- cgit v1.2.3