As shown before, you can create a web API by creating an SHP script as follows:
;; /api/add2
(:api-args (a number?) (b number?))
(+ a b)
Where both a and b are validated as number?. It would be nice if we can validate any type of scheme values, as long as the value can be created via the request input. For example - let's say that you have a struct with the following definition:
(define-struct foo (bar baz))
We want to do the following: (:api-args (foo foo?)) ;; takes in the foo struct
And let web API handle the rest. This is achieved via converters.Converters
The mappings between the request and the api args are done via converters, which maps the parameter key against the type's test function (such asnumber?). And when you want to use the converter in the api-args expression, you specify the <test?> function in the parameter position in one of the following forms: