I am having some basic issues with interceptors
I am trying to write an interceptor to just add some fields to the context object
(defn respond-hello [db request]
{:status 200 :body (str (request->str (jdbc/execute! db ["SELECT * FROM PERSON"]))
"\n"
(request->str request))})
(defn routes [db]
(route/expand-routes
#{["/greet" :get (partial respond-hello db) :route-name ::respond-hello]
["/" :get respond-elm-app :route-name ::spa]}))
(defn start-server
[config db]
(let [attach-system {:enter (fn [context]
(assoc context :context {:db db
:config config}))}]
(-> {:env :dev
::http/routes (routes db)
::http/port (config/server-port config)
::http/type :jetty
::http/join? false}
(http/default-interceptors)
(update :io.pedestal.http/interceptors conj attach-system)
http/create-server
http/start)))
[{:type java.lang.AssertionError
:message "Assert failed: (every? interceptor/interceptor? interceptors)"
:at [io.pedestal.interceptor.chain$enqueue invokeStatic "chain.clj" 273]}]
but I get this
which makes me think that somehow i structured my interceptor wrong
but the error is the same regardless if I have a :name
on the interceptor so i feel at a loss
What you inject there isn't an interceptor yet. You should call io.pedestal.interceptor/interceptor on that map before you inject it.
Hello all. I'm making my first attempt to build an API, and I can't figure out how to get POSTed application/json data. My context in my route handler doesn't seem to have the request body json in it.
Did you look under :request
in the context?
Are you using the io.pedestal.http.body-params/body-params interceptor? If so, you should look under [:request :io.pedestal.http.body-params/body-params]
Thanks. I did finally get past the problem. This seems to give me what I need: `
["/add-event" :post [(io.pedestal.http.body-params/body-params) pusher-api.incoming-data/add-event] :route-name :add-event]
my mistake was not calling body-params ( ). I was just referencing it 😛