12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
(declare (unit api))
(declare (uses rmt))
(declare (uses db))
;; These are called by the server on recipt of /api calls
(define (api:execute-requests db cmd params)
(case (string->symbol cmd)
;; json doesn't do vectors, convert to list
((get-test-info-by-id) (vector->list (apply db:get-test-info-by-id db params)))
((get-key-val-pairs) (apply db:get-key-val-pairs db params))
((test-get-rundir-from-test-id) (apply db:test-get-rundir-from-test-id db params))
(else
(list "ERROR" 0))))
;; http-server send-response
;; api:process-request
;; db:*
;;
;; NB// Runs on the server as part of the server loop
;;
(define (api:process-request db $) ;; the $ is the request vars proc
(let* ((cmd ($ 'cmd))
(paramsj ($ 'params))
(params (rmt:json-str->dat paramsj))
(res (api:execute-requests db cmd params)))
(rmt:dat->json-str
(if (string? res)
res
(list "ERROR" 1 cmd params)))))
|
>
>
>
>
<
>
>
>
>
>
|
>
>
>
|
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
(declare (unit api))
(declare (uses rmt))
(declare (uses db))
;; These are called by the server on recipt of /api calls
(define (api:execute-requests db cmd params)
(debug:print-info 1 "api:execute-requests cmd=" cmd " params=" params)
(case (string->symbol cmd)
;; KEYS
((get-key-val-pairs) (apply db:get-key-val-pairs db params))
;; TESTS
;; json doesn't do vectors, convert to list
((get-test-info-by-id) (vector->list (apply db:get-test-info-by-id db params)))
((test-get-rundir-from-test-id) (apply db:test-get-rundir-from-test-id db params))
((testmeta-get-record) (vector->list (apply db:testmeta-get-record db params)))
;; RUNS
((get-run-info) (let ((res (apply db:get-run-info db params)))
(list (vector-ref res 0)
(vector->list (vector-ref res 1)))))
(else
(list "ERROR" 0))))
;; http-server send-response
;; api:process-request
;; db:*
;;
;; NB// Runs on the server as part of the server loop
;;
(define (api:process-request db $) ;; the $ is the request vars proc
(let* ((cmd ($ 'cmd))
(paramsj ($ 'params))
(params (rmt:json-str->dat paramsj))
(res (api:execute-requests db cmd params)))
(rmt:dat->json-str
(if (or (string? res)
(list? res)
(number? res)
(boolean? res))
res
(list "ERROR" 1 cmd params res)))))
|