This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-07
Channels
- # bangalore-clj (1)
- # beginners (255)
- # boot (29)
- # cider (16)
- # cljs-dev (13)
- # cljsrn (6)
- # clojure (200)
- # clojure-berlin (1)
- # clojure-dev (13)
- # clojure-dusseldorf (6)
- # clojure-greece (1)
- # clojure-india (1)
- # clojure-italy (1)
- # clojure-russia (33)
- # clojure-spec (28)
- # clojure-uk (27)
- # clojurescript (47)
- # cursive (32)
- # data-science (3)
- # datascript (1)
- # datomic (40)
- # emacs (39)
- # events (4)
- # fulcro (55)
- # graphql (16)
- # immutant (2)
- # luminus (2)
- # lumo (5)
- # off-topic (142)
- # onyx (50)
- # portkey (1)
- # re-frame (45)
- # reagent (80)
- # remote-jobs (2)
- # ring-swagger (3)
- # rum (9)
- # schema (3)
- # shadow-cljs (184)
- # spacemacs (3)
- # test-check (4)
- # unrepl (2)
- # yada (5)
Hi fam! I'm having a bit of trouble understanding the syntax for nested, complex routes. I read through the bidi docs but it doesn't seem to quite mesh with the yada examples I've seen. Could I get some advice on how to get this right?
(defn get-email-campaign [ctx] (print "Get campaign"))
(defn create-email-campaign [ctx] (print "create campaign"))
(defn list-email-campaigns [ctx] (print "list campaigns"))
(defn update-email-campaign [ctx] (print "update campaign"))
(def campaign-item-resource
(yada/resource
{:parameters {:path {:clientid String
:userid String
:campaignid String}}
:produces ["application/json"]
:methods
{:get {:response get-email-campaign}
:put {:parameters {:body {:name String
:country String}}
:consumes "application/json"
:response update-email-campaign}}}))
(def campaigns-resource
(yada/resource
{:parameters {:path {:clientid String
:userid String}}
:produces ["application/json"]
:methods
{:get {:response list-email-campaigns}
:post {:parameters {:body {:name String
:country String}}
:consumes "application/json"
:response create-email-campaign}}}))
(defn server-routes []
[""
[["/about" (yada/as-resource "Hello World")]
["/clients"
[[["/" :clientid
[[["/users"
[[["/" :userid
[[["/campaigns"
["/" :campaignid
campaign-item-resource]]
campaigns-resource]]]]]]]]]]]]
["/phone"
[[["/" :number phone-resource]]]]]])
the error I get (but I know my route syntax is wrong) is
clojure.lang.ExceptionInfo: If a PatternSegment is represented by a vector, the second
element must be the keyword associated with the pattern: [[["/users" [[["/" :userid [[["/campaigns"] #yada.resource.Resource{:produces [{:media-type #yada.media_type.MediaTypeMap{:name "application/json", :type "application", :subtype "json", :parameters {}, :quality 1.0}}], :methods {:get {:response #object[smolder_admin_backend.server$get_email_campaign 0x761c3d5f "smolder_admin_backend.server$get_email_campaign@761c3d5f"]}, :post {:response #object[smolder_admin_backend.server$create_email_campaign 0x2d3c2e63 "smolder_admin_backend.server$create_email_campaign@2d3c2e63"], :consumes [{:media-type #yada.media_type.MediaTypeMap{:name "application/json", :type "application", :subtype "json", :parameters {}, :quality 1.0}}], :parameters {:body {:name java.lang.String, :country java.lang.String}}}}, :show-stack-traces? true, :parameters {:path {:clientid java.lang.String}}}]]]]]]]] {}