Liking cljdoc? Tell your friends :D

full.http

Clojars Project

Async HTTP client and server on top of http-kit and core.async

Configuration

The following configuration options are possible (via full.core config loader):

http-timeout: 30 # defaults to 30 (http client request timeout in seconds)

Client

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")))))

Logging

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.

Server

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.

Metrics

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.

Can you improve this documentation? These fine people already did:
Karlis Lauva & Jurģis Krastiņš
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close