This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-31
Channels
- # arachne (4)
- # beginners (21)
- # boot (36)
- # cider (59)
- # cljsrn (8)
- # clojure (260)
- # clojure-filipino (3)
- # clojure-greece (3)
- # clojure-italy (15)
- # clojure-russia (58)
- # clojure-spec (54)
- # clojure-uk (99)
- # clojureremote (5)
- # clojurescript (65)
- # core-matrix (1)
- # cursive (17)
- # data-science (9)
- # datascript (7)
- # datomic (33)
- # emacs (8)
- # hoplon (2)
- # jobs (1)
- # jobs-discuss (2)
- # lein-figwheel (2)
- # lumo (2)
- # numerical-computing (1)
- # off-topic (22)
- # om (78)
- # onyx (17)
- # parinfer (3)
- # pedestal (5)
- # perun (1)
- # powderkeg (19)
- # protorepl (37)
- # re-frame (3)
- # rum (2)
- # spacemacs (1)
- # uncomplicate (8)
- # unrepl (78)
- # untangled (29)
- # yada (41)
Does Yada have some way to use Json schemas, or is there an easy way to convert Json schema to p[ris|lu]matic schema? I found https://github.com/joelittlejohn/js-ps which might do the trick, but be interested if there are other options
it's the other way round I'm looking for - I have an API I want to emulate, which is specified by a JSON schema, I want to plug that into a yada endpoint. I could actually convert it manually, but it'd be nice to slurp in the json schema and use that to validate...
I need to pass additional information to my yada.security/verify
defmethod (configuration data). How do I do this?
@dominicm I’m not sure where to put it. If I put an extra key on the resource, I get a schema error. Also when I put it on the :access-control
map
https://clojurians.slack.com/archives/C0702A7SB/p1490955080102536 this should be in all caps bold at every page of the yada manual
I now have the following resource:
(yada/resource
{:dre/auth-cfg auth-cfg
:access-control
{:scheme “CUSTOM"
:authorization
{:methods
{:get
[:or
"SuperAdmin"
“NormalUser"]}}}
:methods {:get {:produces "text/html"
:response (fn [ctx]
"hello")}}
:responses {403
{:response
sso-redirect}}})
I want this for most of my resources. Just write a function which merges these properties in a yada-resource, or is there some other way to avoid duplication?As auth is not route based in Yada, this is question I have compared to other frameworks
Tree walking with clojure.walk/postwalk is very useful
I now have this:
(yada/resource
(merge (with-default-auth auth-cfg)
{:methods {:get {:produces "text/html"
:response (fn [ctx]
“hello”)}}}))
Looks better already.Any examples of the post walk alternative somewhere @malcolmsparks ?
I’m already content with this solution though. I just write a wrapper for yada/resource which fills in the default auth details.
Can this be abbreviated or does Yada require a set of roles for each method?
:access-control
{:scheme "DRE"
:authorization
{:methods
{:get
[:or
"SuperAdmin"
"DataExtractor"
"DataHub"]
:post
[:or
"SuperAdmin"
"DataExtractor"
"DataHub"]
:put
[:or
"SuperAdmin"
"DataExtractor"
"DataHub"]
:delete
[:or
"SuperAdmin"
"DataExtractor"
“DataHub”]}}}
@borkdude if you want to avoid repitition youcan:
- postwalk the bidi route structure
- use a custom (myapp/resource)
which adds parameters as appropriate
- define a custom access-control thing in the multi-method
More idiomatic Yada for this one?
(fn [ctx]
(let [user-id (get-user-id ctx)
conn (:connection database)
uuid (get-in ctx [:parameters :path :uuid])]
(let [n (db/delete-signal! conn user-id uuid)]
(if (pos? n)
(assoc (:response ctx) :status 200)
(assoc (:response ctx) :status 404)
))))
(the lines with assoc
)so I want to return a 200 when something has been updated, 404 when nothing has been updated
oh yes, that’s a good one, but I was wondering actually if Yada has something less low level for 404 and 200
the 200 for the empty string works though, but it feels a bit weird because normally I return just clojure data
Hmm, this returns a 404:
(yada/response-for (yada/resource {:produces "application/json"
:response (fn [ctx] nil)}))
Trying this:
(yada/response-for
(yada/resource {:produces "application/json"
:response (fn [ctx] nil)})
:get
"/"
{:headers {"Accept" “application/json”}})
Still text/plain.Sorry for flooding this channel in the last 24 hours btw and thanks for helping me get started 😄
@borkdude a manifold Deferred
Or a stream. In the yada training earlier this week we returned manifold subscriptions of an event bus ties to a Datomic tx-report-queue
manifold.stream/map a #(str "data: " % "\n\n") and produce text/event-stream and you have a browsable real time view of your Datomic db. Just works, much more thanks to @ztellman than I
No apologies for flooding this channel- that's what it's for. Stick at it, eventually yada becomes easier.
I have a resource like this:
{
:methods
{:post
{:response (fn [ctx]
(let [res (d/deferred)]
(manifold.time/in 5000
#(d/success! res {:a 10}))
res))}}}
When I fire 20 requests and then request an image in another browser tab img/icon.png
(served from the classpath), it’s still pending for quite some time. Not sure what’s going on.