Liking cljdoc? Tell your friends :D

org.httpkit.client


*default-client*clj

Specifies the default `HttpClient` used by the `request` function.
Value may be a delay. See also `make-client`.
source

aclclj

(acl url & [opts callback])
(acl url & [callback])
Issues an async HTTP ACL request. See `request` for details.
source

copyclj

(copy url & [opts callback])
(copy url & [callback])
Issues an async HTTP COPY request. See `request` for details.
source

default-clientclj

source

default-worker_clj

(delay (new-worker {})), used to handle client callbacks.
See `new-worker` for details.
source

deleteclj

(delete url & [opts callback])
(delete url & [callback])
Issues an async HTTP DELETE request. See `request` for details.
source

getclj

(get url & [opts callback])
(get url & [callback])
Issues an async HTTP GET request. See `request` for details.
source

(head url & [opts callback])
(head url & [callback])
Issues an async HTTP HEAD request. See `request` for details.
source

insecure-clientclj

Client with SNI enabled but hostname verification disabled.
Used when :insecure? is true to allow connections to servers with
mismatched certificates while still supporting SNI for routing.
source

legacy-clientclj

source

lockclj

(lock url & [opts callback])
(lock url & [callback])
Issues an async HTTP LOCK request. See `request` for details.
source

make-clientclj

(make-client {:keys [max-connections address-finder ssl-configurer error-logger
                     event-logger event-names bind-address channel-factory]
              :or {ssl-configurer default-ssl-configurer}})
Returns an HttpClient with specified options:
:max-connections    ; Max connection count, default is unlimited (-1)
:address-finder     ; (fn [java.net.URI]) -> `java.net.SocketAddress`
:channel-factory    ; (fn [java.net.SocketAddress]) -> `java.nio.channels.SocketChannel`
:ssl-configurer     ; (fn [javax.net.ssl.SSLEngine java.net.URI])
:error-logger       ; (fn [text ex])
:event-logger       ; (fn [event-name])
:event-names        ; {<http-kit-event-name> <loggable-event-name>}
:bind-address       ; when present will pass local address to SocketChannel.bind()
source

make-ssl-engineclj

(make-ssl-engine)
(make-ssl-engine ctx)
Returns an SSLEngine using default or given SSLContext.
source

max-body-filterclj

(max-body-filter size)
Returns an IFilter that rejects response bodies over `size` bytes.

Checks both received and automatically decompressed body sizes, so this is
also the mitigation for compressed responses that expand far beyond their
wire size ("zip bombs"). Other IFilter implementations are not applied
after decompression.

Buffered responses have no body-size limit by default.
source

moveclj

(move url & [opts callback])
(move url & [callback])
Issues an async HTTP MOVE request. See `request` for details.
source

new-workerclj

(new-worker {:keys [queue-size n-min-threads n-max-threads prefix
                    allow-virtual?]
             :as opts})
Returns {:keys [n-cores type pool ...]} where `:pool` is a new
`java.util.concurrent.ExecutorService` for handling client callbacks.

When on JVM 21+, uses `newVirtualThreadPerTaskExecutor` by default.
Otherwise creates a standard `ThreadPoolExecutor` with default min and max
thread count auto-selected based on currently available processor count.
source

optionsclj

(options url & [opts callback])
(options url & [callback])
Issues an async HTTP OPTIONS request. See `request` for details.
source

patchclj

(patch url & [opts callback])
(patch url & [callback])
Issues an async HTTP PATCH request. See `request` for details.
source

postclj

(post url & [opts callback])
(post url & [callback])
Issues an async HTTP POST request. See `request` for details.
source

propfindclj

(propfind url & [opts callback])
(propfind url & [callback])
Issues an async HTTP PROPFIND request. See `request` for details.
source

proppatchclj

(proppatch url & [opts callback])
(proppatch url & [callback])
Issues an async HTTP PROPPATCH request. See `request` for details.
source

putclj

(put url & [opts callback])
(put url & [callback])
Issues an async HTTP PUT request. See `request` for details.
source

queryclj

(query url & [opts callback])
(query url & [callback])
Issues an async HTTP QUERY request. See `request` for details.
source

query-stringclj

(query-string m)
(query-string m style)
Returns URL-encoded query string for given params map.
source

reportclj

(report url & [opts callback])
(report url & [callback])
Issues an async HTTP REPORT request. See `request` for details.
source

requestclj

(request {:keys [client timeout connect-timeout idle-timeout filter worker-pool
                 keepalive as follow-redirects max-redirects response
                 trace-redirects allow-unsafe-redirect-methods proxy-host
                 proxy-port proxy-url tunnel? deadlock-guard? auto-compression?
                 insecure? nested-param-style]
          :as opts
          :or {auto-compression? true
               idle-timeout 60000
               proxy-port -1
               tunnel? false
               response (promise)
               follow-redirects true
               proxy-url nil
               as :auto
               deadlock-guard? true
               proxy-host nil
               max-redirects 10
               keepalive 120000
               filter IFilter/ACCEPT_ALL
               connect-timeout 60000}}
         &
         [callback])
Issues an async HTTP request and returns a promise object to which the value
of `(callback {:opts _ :status _ :headers _ :body _})` or
   `(callback {:opts _ :error _})` will be delivered.
The latter will be delivered on client errors only, not on http errors which will be
contained in the :status of the first.

;; Asynchronous GET request (returns a promise)
(request {:url "http://www.cnn.com"})

;; Asynchronous GET request with callback
(request {:url "http://www.cnn.com" :method :get}
  (fn [{:keys [opts status body headers error] :as resp}]
    (if error
      (println "Error on" opts)
      (println "Success on" opts))))

;; Synchronous requests
@(request ...) or (deref (request ...) timeout-ms timeout-val)

;; Issue 2 concurrent requests, then wait for results
(let [resp1 (request ...)
      resp2 (request ...)]
  (println "resp1's status: " (:status @resp1))
  (println "resp2's status: " (:status @resp2)))

RFC 10008 requires QUERY requests to include a `Content-Type` header that
matches the request content.

Returned body type is controlled by `:as` option:

  Without automatic unzipping:
    `:none`           - org.httpkit.DynamicBytes
    `:raw-byte-array` - bytes[]

  With automatic unzipping:
    `:byte-array`     - bytes[]
    `:stream`         - ByteInputStream
    `:text`           - String (charset based on Content-Type header)
    `:auto`           - As `:text` or `:stream` (based on Content-Type header)

Request options:
  :url :method :headers :timeout :connect-timeout :idle-timeout :query-params
  :as :form-params :client :body :basic-auth :user-agent :filter :worker-pool

  :nested-param-style - ∈ #{:comma-separated :array :indexed nil} (default nil)
source

unlockclj

(unlock url & [opts callback])
(unlock url & [callback])
Issues an async HTTP UNLOCK request. See `request` for details.
source

url-encodeclj

(url-encode s)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close