Proof-of-concept of a simple DSL for specifying servlets.

This commit is contained in:
Dominik Pantůček 2025-04-09 10:13:23 +02:00
parent 03c094214b
commit 186fe2d0ec
3 changed files with 33 additions and 5 deletions

View file

@ -33,7 +33,10 @@
(import scheme
spiffy
(chicken format))
(chicken format)
bar-db
json
(chicken port))
(define-syntax try-match-lambda1
(syntax-rules ()
@ -73,8 +76,16 @@
((_ (name . args) . body)
(define name (try-match-lambda args . body)))))
(define (alist->json-string alst)
(with-output-to-string
(lambda ()
(json-write
(list->vector alst)))))
(define-try-match (account-barcode-info "barcode" (barcode string->number))
(send-response #:body (format "API call [barcode] ~A" barcode)))
(send-response
#:body (alist->json-string
`((amount . ,(bd-barcode-lookup barcode))))))
(define api-servlets
(list account-barcode-info))