pedestal

emccue 2020-09-08T19:51:25.014200Z

I am having some basic issues with interceptors

emccue 2020-09-08T19:51:47.014700Z

I am trying to write an interceptor to just add some fields to the context object

emccue 2020-09-08T19:52:16.015Z

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

emccue 2020-09-08T19:53:26.015400Z

[{:type java.lang.AssertionError
   :message "Assert failed: (every? interceptor/interceptor? interceptors)"
   :at [io.pedestal.interceptor.chain$enqueue invokeStatic "chain.clj" 273]}]

emccue 2020-09-08T19:53:29.015600Z

but I get this

emccue 2020-09-08T19:53:43.016Z

which makes me think that somehow i structured my interceptor wrong

emccue 2020-09-08T19:54:24.016500Z

but the error is the same regardless if I have a :name on the interceptor so i feel at a loss

isak 2020-09-08T20:12:14.017400Z

What you inject there isn't an interceptor yet. You should call io.pedestal.interceptor/interceptor on that map before you inject it.

michaelteter 2020-09-08T21:55:28.019Z

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.

isak 2020-09-08T22:17:13.019600Z

Did you look under :request in the context?

isak 2020-09-08T22:19:25.019800Z

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]

michaelteter 2020-09-08T22:21:34.020Z

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]

1
michaelteter 2020-09-08T22:22:14.020300Z

my mistake was not calling body-params ( ). I was just referencing it 😛