diff options
author | Mathieu Othacehe <m.othacehe@gmail.com> | 2017-07-31 19:27:28 +0200 |
---|---|---|
committer | Mathieu Othacehe <m.othacehe@gmail.com> | 2017-09-08 21:15:32 +0200 |
commit | 8a7483a3bbb19b7665de95e652aaf103878be602 (patch) | |
tree | 3752e6ac41227859c6423c657db7947a1231808c /src/cuirass/utils.scm | |
parent | 0a84f0eda0b07bbaa0b38f9916d3be0a1e7acd3f (diff) | |
download | cuirass-8a7483a3bbb19b7665de95e652aaf103878be602.tar cuirass-8a7483a3bbb19b7665de95e652aaf103878be602.tar.gz |
cuirass: add Hydra compatible HTTP API.
* doc/cuirass.texi (Sections)[Web API]: New section describing the HTTP API.
* src/cuirass/http.scm (spec->json-string): Move it to utils.scm and rename it
object->json-string.
(object->json-scm): Move it utils.scm.
(handle-*-request): New helpers procedures.
(request-parameters): New procedure to parse a request query.
(url-handler): Add new API's.
* src/cuirass/utils.scm (object->json-scm, object->json-string): Exported
procedures moved from http.scm.
* tests/http.scm: Add various tests on new HTTP API.
Diffstat (limited to 'src/cuirass/utils.scm')
-rw-r--r-- | src/cuirass/utils.scm | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm index d966543..a932674 100644 --- a/src/cuirass/utils.scm +++ b/src/cuirass/utils.scm @@ -21,9 +21,29 @@ (define-module (cuirass utils) #:use-module (ice-9 match) #:use-module (srfi srfi-1) - #:export (alist?)) + #:use-module (json) + #:export (alist? + object->json-scm + object->json-string)) (define (alist? obj) "Return #t if OBJ is an alist." (and (list? obj) (every pair? obj))) + +(define (object->json-scm obj) + "Prepare OBJ for JSON usage." + (cond ((string? obj) obj) + ((number? obj) obj) + ((boolean? obj) obj) + ((null? obj) obj) + ((symbol? obj) (symbol->string obj)) + ((keyword? obj) (object->json-scm (keyword->symbol obj))) + ((alist? obj) (map object->json-scm obj)) + ((pair? obj) (cons (object->json-scm (car obj)) + (object->json-scm (cdr obj)))) + (else (object->string obj)))) + +(define* (object->json-string object #:key pretty) + "Return OBJECT as a JSON object." + (scm->json-string (object->json-scm object) #:pretty pretty)) |