Created
July 4, 2018 22:09
-
-
Save tonsky/3ae1e1e319c6a3fe8d46dc6beb6e8643 to your computer and use it in GitHub Desktop.
Trouble with bidi routing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; I have this | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
["api/data-init" :api/data-init]]]) | |
;; And I want to make api/data-init only accesible through POST | |
;; I tried | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
[:post ["api/data-init" :api/data-init]]]]) | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
["api/data-init" [:post :api/data-init]]]]) | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
["api/data-init" [[:post :api/data-init]]]]]) | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
{:post ["api/data-init" :api/data-init]}]]) | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
["api/data-init" {:post :api/data-init}]]]) | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
["api/data-init" [:post ["" :api/data-init]]]]]) | |
(def routes ["/" [["" :ui/index] | |
["api/query" :api/query] | |
["api/data-init" {:post ["" :api/data-init]}]]]) | |
;; Also tried replacing `:post` with `{:request-method :post}` in all those cases | |
;; None seemed to work | |
;; It either blew up on me or just didn’t matched the route on request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In bidi, a route is a pair, containing a pattern and a handler. For nested routes, you can replace the handler with a vector of routes.
Line 10 fails because
post
in[:post ["api/data-init" :api/data-init]]
is treated as a pattern, not a (method) guard.Line 14, the
[:post :api/data-init]
is treated as a vector of routes, and:post
is not a route.Line 18, the 'vector of routes' contains one route, which has a single pattern of ':post', which isn't want you want.
Line 22 doesn't have a pattern.
Line 26 is the correct one:
Line 30, see Line 18.
Hope this helps.