Hello,
just a quick and dirty hack I use to get the best of default
dispatch-... for my use-case when dispatching API requests:
(define-for-syntax (dispatch-api-case-helper stx)
(syntax-parse stx
(((method:id (path+args:expr ...) proc:id) rest ...)
#`((("api" path+args ...) #:method #,(symbol->string
(syntax->datum #'method)) proc)
#,@(dispatch-api-case-helper #'(rest ...))))
(((else proc:id))
#'((else proc)))
(()
#'())))
(define-syntax (dispatch-api-case stx)
(syntax-parse stx
((_ rest ...)
#`(dispatch-case
#,@(dispatch-api-case-helper #'(rest ...))))))
(define dispatch-api-request-real
(dispatch-api-case
(get ("number" (number-arg)) api-number-test)
(get ("ping") api-ping)
(post ("auth") auth-login)
(delete ("auth") auth-logout)
(put ("auth") auth-passwd)
(get ("auth" "info") auth-user-info)
(get ("partners") partners-list)
(get ("partners" (string-arg)) partner-detail)
(get ("partners" (string-arg) "payments") partner-payments)
(get ("partners" (string-arg) "debt") partner-debt)
(get ("debts") partners-debts)
(get ("partners" (string-arg) "history") partner-debt-history)
(get ("invoices" "issued") invoices-issued-list)
(get ("invoices" "issued" (string-arg)) invoice-info)
(post ("notes") notes-add)
(else api-404)))
Not very general, but maybe you'll find that useful (especially if the
(string-arg) and similar can make your life easier like it was the case
for me.
When I needed a url-generation function in earlier project, I basically
did the same with more syntax mess around, that used either set! or
parameter from different module to store the dispatch-url -generated
procedure.
Basically it is about customized version of dispatch-rules that does the
dispatch-case and dispatch-url independently and provides the results by
different means.
Cheers,
Dominik