Github user d2r commented on a diff in the pull request:

    https://github.com/apache/incubator-storm/pull/159#discussion_r14796687
  
    --- Diff: storm-core/src/clj/backtype/storm/ui/core.clj ---
    @@ -815,29 +815,35 @@
       [sys?]
       (if (or (nil? sys?) (= "false" sys?)) false true))
     
    -(defn json-response [data & [status]]
    -  {:status (or status 200)
    -   :headers {"Content-Type" "application/json"}
    -   :body (to-json data)})
    +(defn add-padding-to-json [callback response]
    +  (str callback "(" response ");"))
    +
    +(defn json-response
    +  [data callback & [status]]
    +     {:status (or status 200)
    +      :headers (if (not-nil? callback) {"Content-Type" 
"application/javascript"}
    +                {"Content-Type" "application/json"})
    +      :body (if (not-nil? callback) (add-padding-to-json callback (to-json 
data))
    +                (to-json data))})
    --- End diff --
    
    What if instead of deserializing and re-serializing the cluster conf, we 
rewrite `json-response` as a keyword function:
    
    ```Clojure
    (defnk json-response
      [data callback :serialize-fn to-json :status 200]
      {:status status
       :headers (if (not-nil? callback)
                    {"Content-Type" "application/javascript"}
                    {"Content-Type" "application/json"})
       :body (if (not-nil? callback)
                 (add-padding-to-json callback (serialize-fn data))
                 (serialize-fn data))})
    ```
    
    And then for the route to `/api/v1/cluster/configuration`, we can just call:
    
    ```Clojure
    (GET "/api/v1/cluster/configuration" [& m]
      (json-response (cluster-configuration)
                     (:callback m)
                     :serialize-fn identity))
    ```



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to