On 04/04/2016 02:08 PM, Brian Adkins wrote:
(routes
   ("/" home-page)
   ("/:org_shortname/product_image/:style/:filename" product-image #:verbs (get)
    #:name prod-image #:when (regexp-match #rx".jpg$" filename))
   ("/products/(*id).json" product-show #:verbs (get)))

  Any feedback is appreciated.

Good start! One thing I liked about dispatch-rules is that it breaks the url parts up, so you don't have to parse the string. If you could name them, then the part names could be racket identifiers in scope, so you don't have misspelling issues in the #:when function. I'm imagining that the route is essentially a match clause against a url split by '/'. Not sure if I'm making sense, but something like:

(routes
  (route ("")
         home-page)
  (route (org_shortname "product_image" style filename)
         product-image
         #:name prod-image #:methods (get put)
         #:when (regexp-match #rx".jpg$" filename)))

Maybe there's a way to tag url parts with predicates, sort of like dispatch-rules or syntax-parse, but it might obscure the url too much:

(route ((org_shortname string?)
        "product_image"
        (style number?)
        (filename (lambda () (regexp-match #rx".jpg$" filename))))
       #:name prod-image #:methods (get put))

Hope this helps,
Dave

--
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to