Async HTTP client and server on top of http-kit and core.async
The following configuration options are possible (via full.core config loader):
http-timeout: 30 # defaults to 30 (http client request timeout in seconds)
full.http.client
extends http-kit's
httpkit.client/reqest
method and returns the value in a promise channel with
an optional response parser.
(defn github-userinfo> [username]
(full.http.client/req>
{:base-url "https://api.github.com"
:resource (str "users/" username)}))
Default response parser will transform response fields to :kebab-cased
keywords.
HTTP error handling can be done with extra core.async methods provided by full.async:
(defn github-userinfo> [username]
(full.async/go-try
(try
(<?
(full.http.client/req>
{:base-url "https://api.github.com"
:resource (str "users/" username)}))
(catch Exception e
(log/error "user not found")))))
Responses for each HTTP status are logged in a separate logger, so you can control
loglevels for them separately. All of the loggers follow the
full.http.client.$status
naming pattern.
A minimal server example can be found here.
Everything is the same as you'd expect from a stock http-kit + compojure server with the addition that you can return channels as well.
If you enable full.metrics, full.http.server
will report all endpoint
response times to Riemann. The following Riemann can be used to get 95th
percentile data on all endpoints (value for tagged
is whatever you have in
the [tags]
array in metrics configuration):
service =~ "endpoint.%/%0.95" and tagged "service-name" and host = nil
Service name for each endpoint follows the endpoint.$method.$route
naming
scheme, so it's possible to filter requests by method and/or path.