From af02ec582494b52390f5c2d974f8700f39adcf2a Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 12 Jul 2023 04:49:18 -0500 Subject: Handle multi-value --- gn3-guile/web/webserver.scm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'gn3-guile/web') diff --git a/gn3-guile/web/webserver.scm b/gn3-guile/web/webserver.scm index 71ad79c..d7687a0 100755 --- a/gn3-guile/web/webserver.scm +++ b/gn3-guile/web/webserver.scm @@ -79,6 +79,12 @@ (cdr (assoc "bindings" (cdr (assoc "results" response ))))) +(define (sparql-exec query) + "Return list of varnames and list of results" + (let ([response (sparql-scm query)]) + (values (sparql-names response) (sparql-results response)) + )) + (define (sparql-species) (sparql-exec " PREFIX gn: @@ -107,6 +113,10 @@ SELECT DISTINCT ?species ?p ?o WHERE { (define (get-species-all) (sparql-species-meta)) +(define (get-species) + (receive (names results) (sparql-species)) + results) + (define (triples) (array->list (get-species-all))) @@ -118,11 +128,15 @@ SELECT DISTINCT ?species ?p ?o WHERE { ;; ---- REST API web server handler -(define (not-found request) +(define (not-found2 request) (values (build-response #:code 404) - (string-append "Resource not found: " + (string-append "Resource X not found: " (uri->string (request-uri request))))) +(define (not-found uri) + (list (build-response #:code 404) + (string-append "Resource not found: " (uri->string uri)))) + (define (render-json json) (list '((content-type . (application/json))) (lambda (port) @@ -140,6 +154,7 @@ SELECT DISTINCT ?species ?p ?o WHERE { (render-json (get-species))) (('GET "species-all") (render-json (triples))) + (_ (not-found (request-uri request))) )) (define (request-path-components request) -- cgit v1.2.3