This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-12
Channels
- # admin-announcements (1)
- # aleph (1)
- # arachne (10)
- # beginners (6)
- # boot (81)
- # braveandtrue (3)
- # cider (42)
- # cljs-dev (1)
- # cljs-edn (52)
- # cljsjs (9)
- # cljsrn (9)
- # clojure (62)
- # clojure-austin (1)
- # clojure-belgium (11)
- # clojure-berlin (2)
- # clojure-gamedev (2)
- # clojure-greece (1)
- # clojure-russia (73)
- # clojure-uk (98)
- # clojurescript (156)
- # community-development (4)
- # component (3)
- # cursive (30)
- # datascript (10)
- # datomic (17)
- # emacs (5)
- # events (1)
- # hoplon (315)
- # jobs (1)
- # jobs-discuss (3)
- # lein-figwheel (6)
- # luminus (18)
- # off-topic (13)
- # om (130)
- # other-languages (122)
- # re-frame (32)
- # reagent (27)
- # rethinkdb (6)
- # ring (2)
- # ring-swagger (31)
- # spacemacs (4)
- # untangled (6)
- # yada (30)
@malcolmsparks: I’m following this tutorial https://juxt.pro/blog/posts/course-notes-2.html got almost everything working, except this:
(yada/resource
{:methods
{:post
{:consumes transit
:produces transit
:response (fn [ctx]
(let [res (:response ctx)]
(println (str "res -> " res))
yada.context.Response is actually a record, so you can assoc :status and :headers into it, and other things too
If you want to print it, try (println (str "res -> " (into {} res))
The reason you must return this record (or a derivative you've just modified) is to let yada distinguish between a response and a real map
There are times when you want to return real maps (and yada might consider them the body, say in an application/json representation)
@ag hope this helps - I'll check the channel later in case you're having problems
In other words, you usually return a body in a :response function - yada fills in the rest
But in rare occasions you might want to have full control over what is returned - perhaps you need to add a header or set a particular status code - that's the purpose of Response - it's an escape hatch to let you have fine-grained control
other than that. yada, bidi. and that tutorial are truly fantastic!!! thank you very much!
if you just println, then you're effectively returning nil, which will produce a 404, (or the POST equivalent)
oh thank you @ag, that's kind of you
I'm very new to Clojure and Clojurescript, Om Next etc. despite the difficulties. I love it
@malcolmsparks: what I’m seeing is this:
java.lang.ClassCastException: manifold.deferred.SuccessDeferred cannot be cast to clojure.lang.Associative
@ag yada responses are generally promises (aka Deferred
s) of maps, rather than naked maps
you can read about the things you can do with Deferred
s here - https://github.com/ztellman/manifold/blob/master/docs/deferred.md
in short, you can use manifold.deferred/chain
to compose a pipeline of functions to process the value when it is delivered to the promise
@mccraigmccraig: I’m trying to follow Malcolm’s tutorial. https://juxt.pro/blog/posts/course-notes-2.html but it doesn’t work. I feel figwheel is doing something strange
if you are seeing yada errors, i would guess it's probably not figwheel
(I'm with Ag). wrap-cors is showing up in the stack trace and seems to be the culprit.
huh, could be
ah, @ag @danburton is sidecar a ring-handler ?
Sidecar provides a ring server: https://github.com/bhauman/lein-figwheel/blob/47711d65b42251413ca295d28611b90d0181f85f/sidecar/src/figwheel_sidecar/components/figwheel_server.clj#L103
my (second) guess is that you are using a synchronous ring-handler which is trying to modify one of yada's asynchronous responses, which won't work
explanation here - https://github.com/ztellman/aleph/#http
if that's what's happening the simplest thing to do might be to run your api server and figwheel server separately... alternatively you could use a routing lib like bidi to separate sync and async handler paths, so that sidecar never sees a yada response