pedestal

manandearth 2019-03-05T09:51:40.013600Z

Hi there. New to pedestal. Happy to be corrected. I was extending the example in the official pedestal guide (specifically the rest api example: http://pedestal.io/guides/your-first-api) Wanted to implement a :delete interceptor (just in order to understand). tried the following:

(def list-delete
 {:name :list-delete                                                                                                  
  :enter
   (fn [context]
      (let [nm (get-in context [:request :query-params :name]) 
            db-id (filter (comp #{nm} (:tx-data context)) (keys (:tx-data context)))] 
        (update context :tx-data dissoc db-id)))}) 
the original interceptor that creates the list is:
(def list-create   
   {:name :list-create 
    :enter
    (fn [context]
      (let [nm       (get-in context [:request :query-params :name] "Unnamed List")
            new-list (make-list nm)
            db-id    (str (gensym "l"))] 
        (assoc context :tx-data [assoc db-id new-list])))}) 
the original route for the :post is: ["/todo" :post [db-interceptor list-create]] so my :delete root is: ["/todo" :delete [db-interceptor list-delete]] But trying the test: (test-request :delete "/todo?name=some-list") when the state is:
{"l30491" {:name "my-other-list", :items {}}, "l30517" {:name "yes-list", :items {}}, "l30520" {:name "no-list", :items {}}, "l30527" {:name "no-list", :items {}}, "l30618" {:name "some-list", :items {}}} 
does not delete the list in question.... Note that some-list is the :name value in a map which is a value of the string "l30618" ... I think that my list-delete function should do the job, but I suspect that I don't understand something basic either about interceptors or about how :delete should be called in a REST api....

2019-03-05T22:06:14.014800Z

@adamgefen At a glance, it doesn’t look like your list-delete impl is correct

2019-03-05T22:06:36.015100Z

the filter expression looks wrong