-
Notifications
You must be signed in to change notification settings - Fork 149
Async
Tommi Reiman edited this page Apr 4, 2017
·
11 revisions
Compojure-api supports the new async ring.
- Endpoints can return either manifold
Deferred
or core.asyncManyToManyChannel
s. - 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)))
TODO
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