Re: Question about generating urls with dispatch-rules from imported modules

Yury Bulka <setthemfree-tGttlkr9q/[email protected]> Sun, 26 Apr 2020 18:26:30 +0300
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <[email protected]>
Meanwhile here's my attempt at doing a koyo-like url generation with a
wrapper around web-server/dispatch's url-generating function:

(define-values (app-dispatch app-url)
  (dispatch-rules  ; the standard one
   [...]))

(define (app-url/names route-name . args)
  ;; define a mapping between symbolic names and handlers
  (define route-names
    (hash 'item-list item-list-view
          'item-detail item-detail-view))
  (apply app-url (hash-ref route-names route-name) args))

And then I can store the function in a parameter that is used by the
templates.

It is of course not a general solution (for instance, the rules in
dispatch-rules and the route-names can go out of sync if one forgets to
update either of them) and they are not dynamic.

But for an ultra-minimalistic application this might do when you don't
feel like adding a new external dependency.

--
Yury Bulka
https://mamot.fr/@setthemfree
#NotOnFacebook



Yury Bulka <setthemfree-tGttlkr9q/[email protected]> writes:

> Thank you for sharing this!
>
> I'm wondering, if this is a common use case, maybe it is worth adding to
> web-server/dispatch in some form?
>
> Or, if not, maybe we can extend the documentation to include some hints
> on how to approach this otherwise?
>
> It is great to have powerful libraries outside the main distribution,
> but the main distribution is the place where newcomers like me are going
> to look first.

-- 
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/87o8rei7yx.fsf%40privacyrequired.com.