Fork me on GitHub
Kari Pahula13:07:18

I'm new to Clojure and Reitit so it could be just that I've misunderstood something basic. I'm looking at and how it sets its parameters with :parameters {:body {:x int?, :y int?}} in the "plus with spec body parameters" route. Is it possible to use a richer spec in there instead of just defining query parameters? Should I look at spec-tools or spec.alpha or both or netiher? I'd like to ultimately pass json to my route and I don't know if this is the way it should be done.


Hi @kari.pahula! The example you posted :parameters {:body {:x int?, :y int?}} is actually defining what a body of a POST request should look like (a map with keys :x and :y where their values satisfy the predicate int?). The data could come in as JSON or EDN or whatever and it's read into Clojure data structures by muuntaja. Muuntaja can deal with several transport formats, including JSON. You can define arbitrarily complex specs with both spec.alpha and spec-tools and it should "just work" with Reitit afaik. spec-tools provides bunch of extra functionality and convenience on top of spec.alpha.

Kari Pahula05:07:44

Well, quite. I must have misunderstood the swagger ui or something. I ran the ring-swagger example again and it does indeed accept curl -i -d '{"x":5, "y":2}' -H 'Content-Type: application/json'.