juxt

martinklepsch 2018-05-09T13:07:19.000010Z

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?

martinklepsch 2018-05-09T13:11:01.000490Z

(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…

martinklepsch 2018-05-09T13:14:15.000087Z

hm, that doesn’t work:

No implementation of method: :resolve-handler of protocol: #’bidi.bidi/Matched found for class: cljdoc.server.doc_pages.DocPage

martinklepsch 2018-05-09T13:35:20.000645Z

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

dominicm 2018-05-09T13:37:07.000187Z

same kind of thing, bidi has a protocol for "how to make a handler from this"

martinklepsch 2018-05-09T13:45:05.000415Z

@dominicm I think I found some relevant code…

martinklepsch 2018-05-09T13:45:23.000184Z

(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))))
      “”)))

martinklepsch 2018-05-09T16:19:17.000012Z

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"]}?

dominicm 2018-05-09T16:19:56.000795Z

There's something about :path-info? in yada, but it's done via a bidi protocol

dominicm 2018-05-09T16:20:10.000388Z

Oh, you have that already

dominicm 2018-05-09T16:20:15.000348Z

so yeah, just add :path-info? true

martinklepsch 2018-05-09T16:24:14.000817Z

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?

dominicm 2018-05-09T16:24:52.000608Z

yeah, you just get the whole thing.

martinklepsch 2018-05-09T16:25:21.000717Z

ah remainder is a thing