Hi, how would I go about adding a custom Last-Modified
header to all responses at router level? I’m assuming this should be done at a response coercion level but I’m not sure how to wire it up.
hi, I have some name-based routing in a project and I would like to add more methods to the same route path. Something like this:
["/add"
{:name :my-route/list
:get {:handler ...}}
{:name :my-route/create
:post {:handler ..}}]
This snippet does not work, what is the proper way to achieve this? thanks!Hi...like this
["" {:get {:handler (search app-config)
:parameters {:query specs/search}
:swagger {:produces [poi-search-api-version]}}
:post {:handler (create app-config)
:parameters {:body specs/create}
:swagger {:produces [poi-create-api-version]}}}]
but I would like to keep the :name
key.. On testing I've been using match by name on other endpoints
Don't know then
IIRC :name
matches just the route, not the method
["" {:name :my-route
:get {:handler (search app-config)
:parameters {:query specs/search}
:swagger {:produces [poi-search-api-version]}}
:post {:handler (create app-config)
:parameters {:body specs/create}
:swagger {:produces [poi-create-api-version]}}}]
(get (match-by-name routes :my-route) ...)
(post (match-by-name routes :my-route) ...)
:thumbsup:
got it, thanks @juhoteperi and @dharrigan
np
So I see that `reitit` supports `malli` (of course), and `reitit` supports `swagger`, and `malli` supports `swagger`. But... can I use `malli` on my `reitit` routes and produce `swagger` docs in one fell swoop?
@jmckitrick see https://github.com/metosin/reitit/tree/master/examples/ring-malli-swagger
Thanks!
Well, my current codebase will not let me switch to Malli at the moment.
So my question now is about the 'or' specs, such as (s/or :string spec/string? :int spec/number?)
How can I make swagger show the string as the preferred type? The order of the specs does not seem to matter... 'int' appears to take precedence.
spec doesn't support metadata, but you could wrap you spec into spec-tools.core/schema
, something like (st/schema (s/or ...) {:swagger/type "string"})
. Not at computer, so the syntax might be wrong.
it's basically a no-op wrapper with support for metadata (among other add-ons)
So that wouldn't require moving away from our current 'data spec' use on endpoints? I'll be adding more spec to other endpoints, but I would like to stay consistent.
well, that's one of the root causes for developing malli: data-specs (or plumatic) syntax is good for simple things, but gets messy when one needs to add things like meta-data. You can mix data-specs and specs, but it's two systems instead of one.
if there are ideas how to extend data-specs to support metadata without tears, happy to add that.
I'm afraid tears will be part of my job, lol.
I'm looking for the 'schema' function to add metadata, and I'm not seeing it...
Going to browse the ns and keep looking...
oh, st/spec
Aha! Thanks
Those look like all predicates....
https://cljdoc.org/d/metosin/spec-tools/0.10.5/doc/swagger2#annotated-specs
Hi 👋! Is there a way to gradually migrate a giant api server built with compojure to reitit routing? I'd like to showcase a small working example within my organization without having to rewrite the world. Thanks 🙏
Maybe:
(def compojure-app
(c/GET "/old" [] handler)
(def reitit-app
(rr/ring-handler
(rr/router
["/new" {:get handler}])))
(def app
(rr/routes compojure-app reitit-app))
... then move stuff one by one. I recommend to run a perf test before and after (full migration)
Oh! Really cool. Thanks; I will try that!
Hello again, I wonder if anyone’s got any ideas for the response headers Q? (sorry to double post, I’ve just not had any luck looking through the codebase or docs for this) https://clojurians.slack.com/archives/C7YF1SBT3/p1615378184014600
@jen you should mount a middleware to all routes for that. It's all ring: all request/response handling is done either in the mw (reusable) or in the handler.
thanks I’ll go hunt in ring docs rather than reitit then for wiring up examples. Thanks!