1. Integrant components
  2. :http.client/hato

Integrant components


Component that creates a hato HTTP client for use throughout your application.

For example, you may configure it as follows in your system.edn

{:connect-timeout 3000}

And as follows in your Clojure code:

(derive :http.client.hato/auth0 :http.client/hato)

Note the derivation allows you to have multiple clients should you want one per individual service

Now you can use this component throughout the application, e.g.

;; system.edn
{:base-path "/api"
 :env #ig/ref :system/env
 :auth0-http-client :http.client.hato/auth0}

;; clojure (in default template your <<app-name>>.web.routes.api)
(defn auth0-call
  (-> (hato/get "https://YOUR_DOMAIN/wsfed/YOUR_CLIENT_ID"
                {:http-client (utils/route-data-key req :auth0-http-client)})

(defn api-routes [base-path]
    {:get {:no-doc  true
           :swagger {:info {:title " API"}}
           :handler (swagger/create-swagger-handler)}}]
    {:get health/healthcheck!}]
   ;; New code here
    {:post auth0-call}]])

http.client/hato is derived from http/client. This is useful should you want to extend behaviour for multiple HTTP clients and want to apply the same logic across all of them.