 
 (defroutes task-service
   (ANY "/task" {:keys [request-method db body]}
-       (let [data (when (= request-method :post) (as-json body))
+       (let [data (when (= request-method :post) (as-json body :key-fn keyword))
              new-id (when (= request-method :post)
                       (let [r (next-task-id db)]
                         (or (:newid (first r)) 0)))]


;;; utilities

(defn as-json [obj]
  (condp instance? obj
    String (json/read-str obj)
    java.io.InputStream (json/read (io/reader obj))
    java.io.Reader (json/read (io/reader obj))
    obj))

;;; services


           :available-media-types ["application/json"]
           :handle-ok (list-tasks db)
           :handle-malformed (pr-str data)
           :post! (fn [ctx] (new-task! db new-id (:title data)))
           :handle-created {:id new-id})))

  (ANY "/task/:id" [id :as {:keys [request-method db body]}]
       (let [data (when (= request-method :put) (as-json body :key-fn keyword))]
         (resource
           :allowed-methods [:get :put :delete]
           :available-media-types ["application/json"]
           :malformed? (and (= request-method :put) (nil? data))
           :handle-ok (fn [_] (first (get-task db)))
           :put!  (fn [_] (update-task! db (:title data) id))
           :new? false
           :delete! (fn [_] (delete-task! db id))))))

