Fork me on GitHub
#yada
<
2017-06-25
>
nha20:06:05

Question: did anyone give some thoughts to declaring the paths in the resources? Good idea/bad idea?

(yada/resource {:custom/path  "/api/path"
                :methods {:get {:response (fn [ctx]
                                            (assoc ctx :body "ok"))}}})

malcolmsparks20:06:42

No real problem with it. It's all data after all @nha. But you are fixing a one-to-one cardinality between paths and resources there. Generally I encourage separation of identity and resource.

nha20:06:26

Wouldn't something like that allow a resource to be accessible through multiple paths?

(yada/resource {:custom/path (->MultiPath
                               "/api/path"
                               "/api/another-path")
                :methods {:get {:response (fn [ctx]
                                            (assoc ctx :body "ok"))}}})
I guess what constitutes the identity vs what is the resource is not clear to me. I will have to read about it 🙂

malcolmsparks20:06:03

A URI is different from the web resource. URIs are specified in a different (earlier) RFC to HTTP. For example, @nha is an idenifier and identifies you, but is not you.

nha20:06:54

Ah that makes sense, thanks 🙂

nha22:06:08

(yada/response-for (yada/resource {:methods {:get {:produces [{:media-type #{"application/json;q=0.9"
                                                                             "application/transit+json;q=0.8"
                                                                             "application/edn;q=0.7"
                                                                             "text/html;q=0.6"}
                                                               :charset "UTF-8"}]
                                                   :response (fn [ctx]
                                                               {:content "some-content"})}}})
                   :get
                   "ignore-me"
                   {:headers {"content-type" "application/edn"}})
This returns a map with :headers "content-type" "application/json", and the :body is JSON indeed. How do I get edn or transit in the :body ?

thegeez22:06:51

@nha use {:headers {"accept" "application/edn"}}