I really like it when my bidi routes are plain data but when working with yada it seems common to just replace the route-id keywords with resources. Is there some way to maintain that separation?
(defrecord DocPage [page-type]
yada.resource/ResourceCoercion
(as-resource [_]
(yada/resource
{:id page-type
:description "The description to this example resource"
:summary "An example resource"
:produces "text/html"
:methods {:get (fn [_] "hello world")}})))
(->DocPage :my-id)
does something like this seem reasonable? This way my route leaves would be basic records…hm, that doesn’t work:
No implementation of method: :resolve-handler of protocol: #’bidi.bidi/Matched found for class: cljdoc.server.doc_pages.DocPage
Extending it with bidi’s protocols gets me to
No implementation of method: :request of protocol: #’bidi.ring/Ring found for class: cljdoc.server.doc_pages.DocPage
same kind of thing, bidi has a protocol for "how to make a handler from this"
@dominicm I think I found some relevant code…
(defrecord DocPage [page-type]
yada.resource/ResourceCoercion
(as-resource [_]
(yada/resource
{:id page-type
:description “The description to this example resource”
:summary “An example resource”
:produces “text/html”
:methods {:get (fn [_] (str “hello world ” page-type))}}))
bidi.bidi/Matched
(resolve-handler [this m]
(let [r (yada.resource/as-resource this)]
(if (:path-info? r)
(assoc m :handler r)
(bidi.bidi/succeed r m))))
(unresolve-handler [this m]
(when
(or (= this (:handler m))
(and page-type (= page-type (:handler m))))
“”)))
is there a way to match all URI segments after a given /
into a collection?
e.g. /article/section1/section2/123
=> {:article-path ["section1" "section2" "123"]}
?
There's something about :path-info?
in yada, but it's done via a bidi protocol
Oh, you have that already
so yeah, just add :path-info? true
ah neat. it’s matching the URI now but additional segments are not part of the route-params. I assume I have to sort this out myself?
yeah, you just get the whole thing.
ah remainder
is a thing