Skip to content
Tommi Reiman edited this page Apr 4, 2017 · 11 revisions

Compojure-api supports the new async ring.

See Async example project.

Async handlers & middleware

  • Endpoints can return either manifold Deferred or core.async ManyToManyChannels.
  • Endpoints and Middleware can be invoked with CPS-style enabling custom async.
(require '[compojure.api.sweet :refer :all])
(require '[ring.util.http-response :refer :all])
(require '[manifold.deferred :as d])
(require '[aleph.http :as http])

(GET "/repository/:repository/downloads" []
  :summary "Async gets the clojars download count"
  :path-params [repository :- String]
  :return Long
  (d/chain
    (http/get
      (str "https://clojars.org/api/artifacts/" repository)
      {:as :json, :throw-exceptions false})
    :body
    :downloads
    #(or % 0)
    (ok)))

Streaming Responses

TODO

Adapters

Ring-adapters (for different web-servers) need to support the async ring. Here's a list of adapters supporting that currently:

Should work, need manual bootstrapping:

  • Aleph
  • HttpKit
  • Immutant