chickadee » uri-match » make-uri-matcher

make-uri-matcher routesprocedure

Accepts a routes list in the format described under Routes Format and returns a procedure of two arguments (method and uri like uri-match) for matching against it.

Example:

(use uri-common)

(define match (make-uri-matcher `(((/ "") (GET "this is the root path!")
				   ((/ "some")
				    ((/ "nested") (GET "I'm nested!")
				     ((/ (submatch (+ num)))
				      (POST ,(lambda (continue n)
					       (if (< (string->number n) 10) 
						   "what a humble number!"
						   (continue)))))
					      
				     ((/ "route" (submatch (+ any)) (submatch (+ any)))
				      (GET ,(lambda (continue x y)
					      (format "I am the ~A and ~A!" x y)))))
				    
				    ((/ (submatch (+ any)) (submatch (+ any)))
				     (POST ,(lambda (continue x y)
					      (format "You've requested ~A" y)))))))))

((match 'GET "/"))
=> "this is the root path!"

((match 'GET (uri-reference "http://localhost/some/nested/route/alpha/omega")))
=> "I am the alpha and omega!"

((match 'POST "/some/nested/2"))
=> "what a humble number!"

((match 'POST "/some/nested/12"))
=> "You've requested 12"