Hello,

I would go for 'methods instead of 'verbs, a HTTP vocabulary instead of a REST one.

For the pathinfo:

When using a string you use :pattern as place holder as far as i know there is no such convention in racket, maybe you should explore ~pattern (like format), #:pattern, 'pattern, #'pattern (like macro templating) or at-expr?

For constraints on placeholders you may want to limit them to regexp because:

1. 99.999% of the time they will satisfy the developer needs.
2. You give you room to make your router fast implementing a minimal final state machine (a regexp).

example:

("/~org-shortname/product_image/~style/~filename"
 #:method POST
 #:constraints ([filename ".*\\.xml$"])
 ;; a guard that break optimisations and expand
 #:when (not (equal? "abc" org-shortname))
 #:controller my-controller)


Or maybe use a list like dispatch-rule

((org-shortname "product_image" style filename)
 #:method POST
 #:constraints ([filename ".*\\.xml$"])
 ;; a guard that break optimisations and expand
 #:when (not (equal? "abc" org-shortname))
 #:controller my-controller)




On 04/04/2016 08:08 PM, Brian Adkins wrote:
I've been looking into an appropriate syntax for routing web requests. For each 
route, I'll need the following information:

* URL Pattern (required) e.g.
   "/"
   "/:org_shortname/product_image/:style/:filename"
   "/:org_shortname/products/(*id).json"

* Function to handle request (required)

* Accepted HTTP verbs (optional, defaults ot all)

* Name (optional) - used to do "reverse routing" i.e. produce a URL from 
parameters

* Contraints (optional) - further refine the pattern matching e.g. type/format 
of params

Here's an example from Rails:

Foo::Application.routes.draw do
   match "/:org_shortname/product_image/:style/:filename" => 
'product_images#product_image',
     :as => :product_image, :via => :get, :constraints => { :filename => 
/.jpg$/ }

   # URL pattern: "/:org_shortname/product_image/:style/:filename"
   # Function: ProductImagesController.product_image
   # Name: :product_image
   # Verbs: GET
   # Contraints: filename param must end in .jpg

   match '/products/(*id).json'  => 'products#show', :via => :get

   # URL pattern: '/products/(*id).json'
   #    (*id) globs everything between /products/ and .json including / chars
   # Function: ProductsController.show
   # Verbs: GET
end

There are many other aspects (much of which is just syntax sugar) of routing in 
Rails that I'm ignoring initially.

I'm thinking of something like the following:

(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)))

The first two arguments (url-pattern function) are required, so they're 
positional. The optional arguments are specified with keywords.

Instead of:  #:verbs (get)    would it be better to have  #:verbs get  and 
dynamically check for an atom vs. list ?

My initial goal is just for the "base" syntax. Sugar can be added later for 
some cases.

  Any feedback is appreciated.

Thanks,
Brian


--
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