(client)(client opts)(client client opts)Creates new client from opts or creates a new client from a client,
copying it's settings and extra opts. Returned client can be used with
request.
Options:
:call-timeout (in ms):read-timeout (in ms):write-timeout (in ms):connect-timeout (in ms):protocols - one of "http/1.0", "http/1.1", "h2", "h2_prior_knowledge", "quic", "spdy/3.1", "h3":dispatcher : map of :executor, :max-requests, :max-requests-per-host:connection-pool : map of :max-idle-connections, :keepalive-duration (in ms):retry-on-connection-failure:follow-redirects:ssl-socket-factory - tuple of [ssl-socket-factory trust-manager]:tls - map of :ca, :cert, :key: :ca alone to trust a custom CA,
:cert + :key for client certificates (with optional :ca):follow-ssl-redirects:proxy - java.net.Proxy or map of :host, :port, :type (:http
default, or :socks):proxy-selector - java.net.ProxySelector:proxy-authenticator - okhttp3.Authenticator:hostname-verifier:authenticator:cache:event-listener:event-listener-factory:add-network-interceptors:add-interceptorsCreates new `client` from `opts` or creates a new `client` from a `client`, copying it's settings and extra `opts`. Returned client can be used with `request`. Options: * `:call-timeout` (in ms) * `:read-timeout` (in ms) * `:write-timeout` (in ms) * `:connect-timeout` (in ms) * `:protocols` - one of "http/1.0", "http/1.1", "h2", "h2_prior_knowledge", "quic", "spdy/3.1", "h3" * `:dispatcher` : map of `:executor`, `:max-requests`, `:max-requests-per-host` * `:connection-pool` : map of `:max-idle-connections`, `:keepalive-duration` (in ms) * `:retry-on-connection-failure` * `:follow-redirects` * `:ssl-socket-factory` - tuple of `[ssl-socket-factory trust-manager]` * `:tls` - map of `:ca`, `:cert`, `:key`: `:ca` alone to trust a custom CA, `:cert` + `:key` for client certificates (with optional `:ca`) * `:follow-ssl-redirects` * `:proxy` - `java.net.Proxy` or map of `:host`, `:port`, `:type` (`:http` default, or `:socks`) * `:proxy-selector` - `java.net.ProxySelector` * `:proxy-authenticator` - `okhttp3.Authenticator` * `:hostname-verifier` * `:authenticator` * `:cache` * `:event-listener` * `:event-listener-factory` * `:add-network-interceptors` * `:add-interceptors`
(connect request-map)(connect client request-map)Performs a CONNECT http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a CONNECT http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(def-http-method method)(delete request-map)(delete client request-map)Performs a DELETE http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a DELETE http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(get request-map)(get client request-map)Performs a GET http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a GET http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(head request-map)(head client request-map)Performs a HEAD http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a HEAD http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(options request-map)(options client request-map)Performs a OPTIONS http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a OPTIONS http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(patch request-map)(patch client request-map)Performs a PATCH http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a PATCH http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(post request-map)(post client request-map)Performs a POST http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a POST http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(put request-map)(put client request-map)Performs a PUT http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a PUT http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
(request request-map)(request client request-map)Performs an HTTP request using the provided OkHttp client and a request map. Returns a Ring-style response map containing keys such as :status, :headers, :body.
Arguments:
client (okhttp3.OkHttpClient): Optional, if not provided the default client is used.request-map (map): Map describing request parameters.Supported keys in request-map:
:method - HTTP method keyword (:get, :post, etc), defaults to :get:url - Absolute URL string (required):headers - Map of header names to values:body - Request body (string, bytes, stream, file, etc.). InputStream
bodies (including :multipart contents) are always closed by the time
request returns or throws:query-params - Map of query parameters to add to URL:form-params - Map of form fields, sent as
application/x-www-form-urlencoded. Sequential values add repeated fields:multipart - Sequence of parts sent as multipart/form-data, each a map
of :name, :content (anything accepted by :body) and optional
:filename, :content-type
:body takes precedence over :multipart, which takes precedence over
:form-params.Options:
:throw-on-error - If true (default), throws exception on 4xx/5xx. If false, returns response.:call-timeout - Timeout for this call (in ms), overriding the client's
:call-timeout. Covers the whole call, including reading the body. For
other client options, derive a client with (client client opts):response-body-decoder - Decoding strategy for :body:
:string (default) - eager, decoded using the response charset:bytes - eager byte array:input-stream - eager copy, safe to leave unclosed:byte-stream - lazy stream over the connection, the caller MUST close
it (e.g. with-open) or the connection leaks. On errors thrown via
:throw-on-error the body is read eagerly insteadReturns:
:url is the final URL after redirects, :protocol
the negotiated protocol (e.g. "http/1.1", "h2"). Headers with
multiple values are vectorsExample: (request {:method :get :url "https://httpbin.org/get"}) (request client {:method :post :url "https://api.com" :headers {"Content-Type" "application/json"} :body "{...}"})
Performs an HTTP request using the provided OkHttp client and a request map.
Returns a Ring-style response map containing keys such as :status, :headers, :body.
Arguments:
* `client` (okhttp3.OkHttpClient): Optional, if not provided the default client is used.
* `request-map` (map): Map describing request parameters.
Supported keys in `request-map`:
* `:method` - HTTP method keyword (:get, :post, etc), defaults to :get
* `:url` - Absolute URL string (required)
* `:headers` - Map of header names to values
* `:body` - Request body (string, bytes, stream, file, etc.). InputStream
bodies (including `:multipart` contents) are always closed by the time
`request` returns or throws
* `:query-params` - Map of query parameters to add to URL
* `:form-params` - Map of form fields, sent as
`application/x-www-form-urlencoded`. Sequential values add repeated fields
* `:multipart` - Sequence of parts sent as `multipart/form-data`, each a map
of `:name`, `:content` (anything accepted by `:body`) and optional
`:filename`, `:content-type`
`:body` takes precedence over `:multipart`, which takes precedence over
`:form-params`.
Options:
* `:throw-on-error` - If true (default), throws exception on 4xx/5xx. If false, returns response.
* `:call-timeout` - Timeout for this call (in ms), overriding the client's
`:call-timeout`. Covers the whole call, including reading the body. For
other client options, derive a client with `(client client opts)`
* `:response-body-decoder` - Decoding strategy for :body:
* `:string` (default) - eager, decoded using the response charset
* `:bytes` - eager byte array
* `:input-stream` - eager copy, safe to leave unclosed
* `:byte-stream` - lazy stream over the connection, the caller MUST close
it (e.g. `with-open`) or the connection leaks. On errors thrown via
`:throw-on-error` the body is read eagerly instead
Returns:
* Ring response map: {:status int, :headers map, :body value, :url string,
:protocol string}. `:url` is the final URL after redirects, `:protocol`
the negotiated protocol (e.g. "http/1.1", "h2"). Headers with
multiple values are vectors
Example:
(request {:method :get :url "https://httpbin.org/get"})
(request client {:method :post :url "https://api.com" :headers {"Content-Type" "application/json"} :body "{...}"})
(shutdown! client)Closes all connections and releases resources for the provided OkHttpClient instance. This will:
(client client opts) share their connection pool and
dispatcher with the client they derive from, so shutting down one shuts
down both. Do not call it on default-client.Closes all connections and releases resources for the provided OkHttpClient instance. This will: - Evict all connections from the internal connection pool - Shutdown the underlying executor service - Close the cache, if present Call this when you are done with an OkHttpClient to avoid resource leaks. Clients derived via `(client client opts)` share their connection pool and dispatcher with the client they derive from, so shutting down one shuts down both. Do not call it on `default-client`.
(trace request-map)(trace client request-map)Performs a TRACE http request via client, using request-map as payload.
Returns a ring response map
Options:
:throw-on-error - defaults to true
:response-body-decoder - :string (default), :bytes,
:input-stream (eager copy) or :byte-stream (lazy, the caller MUST close
it). See request
Performs a TRACE http request via `client`, using `request-map` as payload. Returns a ring response map Options: * `:throw-on-error` - defaults to true * `:response-body-decoder` - `:string` (default), `:bytes`, `:input-stream` (eager copy) or `:byte-stream` (lazy, the caller MUST close it). See `request`
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |