clojurehttp-kit

http-kit what is the difference between sending response through channel and just return a map


As the title says. What is the difference between sending response through a channel and just return a map.

(defn handler-one
  [request]
  (response "hello world")

(defn handler-two
  [request]
  (with-channel request channel
    (send! channel (response "hello world"))

Solution

  • handler-one function uses synchronous approach. Request -> Response

    handle-two is a way to achieve Request -> Response but asynchronously.

    You can check with-channel macro definition for more implementation details (and documentation).

    If you want more details about asynchronous approach in general, then I recommend learning about one of: Futures, Reactive Programming, Netty, Node.js or Vert.x