Skip to content

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

License

Notifications You must be signed in to change notification settings

fullcontact/full.http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published