This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-02
Channels
- # announcements (3)
- # aws (2)
- # babashka (60)
- # beginners (21)
- # cljs-dev (35)
- # cljsrn (3)
- # clojure (53)
- # clojure-android (2)
- # clojure-australia (3)
- # clojure-europe (45)
- # clojure-france (4)
- # clojure-nl (4)
- # clojure-uk (6)
- # clojurescript (33)
- # core-typed (1)
- # cursive (13)
- # datomic (6)
- # duct (1)
- # emacs (2)
- # fulcro (10)
- # introduce-yourself (3)
- # jobs (2)
- # jobs-discuss (13)
- # leiningen (1)
- # malli (19)
- # missionary (63)
- # music (1)
- # off-topic (21)
- # pathom (3)
- # polylith (18)
- # practicalli (12)
- # proletarian (1)
- # reagent (40)
- # reitit (23)
- # releases (1)
- # remote-jobs (1)
- # ring (14)
- # ring-swagger (1)
- # shadow-cljs (13)
- # sql (30)
- # testing (27)
- # tools-deps (31)
- # vim (10)
- # xtdb (4)
Hi @raymcdermott I tried it out myself, and apart from a small change, it works as I would expect:
(defn routes
[]
["/api"
["/episodes"
{:swagger {:tags ["episodes"]}
:post {:summary "persist data for the episode"
:parameters {:body [:map [:number int?]]}
:responses {200 {:body [:map [:number int?]]}}
:handler (fn [{{{:keys [number]} :body} :parameters}]
(println :number number)
{:status 200 :body {:number number}})}}]
["/episodes/:number"
{:swagger {:tags ["episodes"]}
:get {:summary "fetch data for the episode"
:parameters {:path [:map [:number int?]]}
:responses {200 {:body [:map [:number int?]]}}
:handler (fn [{{{:keys [number]} :path} :parameters}]
(println :number number)
{:status 200 :body {:number number}})}}]])
The handler still needs to return the correct response (the :responses
only validates it)
❯ http --verbose POST :18081/api/episodes number:=1
POST /api/episodes HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 13
Content-Type: application/json
Host: localhost:18081
User-Agent: HTTPie/2.4.0
{
"number": 1
}
HTTP/1.1 200 OK
Content-Length: 12
Content-Type: application/json;charset=utf-8
{
"number": 1
}
❯ http --verbose :18081/api/episodes/1
GET /api/episodes/1 HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Host: localhost:18081
User-Agent: HTTPie/2.4.0
HTTP/1.1 200 OK
Content-Length: 12
Content-Type: application/json;charset=utf-8
{
"number": 1
}
(defn routes
[app-config]
["/api"
["/episodes"
["" {:swagger {:tags ["episodes"]}
:post {:summary "persist data for the episode"
:parameters {:body [:map [:number int?]]}
:responses {200 {:body [:map [:number int?]]}}
:handler (fn [{{{:keys [number]} :body} :parameters}]
(println :number number)
{:status 200 :body {:number number}})}}]
["/:number" {:swagger {:tags ["episodes"]}
:get {:summary "fetch data for the episode"
:parameters {:path [:map [:number int?]]}
:responses {200 {:body [:map [:number int?]]}}
:handler (fn [{{{:keys [number]} :path} :parameters}]
(println :number number)
{:status 200 :body {:number number}})}}]]])
I also have a further, more detailed route setup on a little show-and-tell project I use
I am also annoyed with this issue https://clojurians.slack.com/archives/C7YF1SBT3/p1627471462212300 Could someone help?
@dharrigan thanks for the suggestions and for the link - I'm making progress 🙂
:number 1 :arg2 #object[reitit.ring.coercion$fn__10487$fn__10489$fn__10490$fn__10491 0x729976a2 reitit.ring.coercion$fn__10487$fn__10489$fn__10490$fn__10491@729976a2] :arg3 #object[reitit.ring.coercion$fn__10500$fn__10502$fn__10503$fn__10506 0x1651e4bc reitit.ring.coercion$fn__10500$fn__10502$fn__10503$fn__10506@1651e4bc]