clj-http.client documentation

Batteries-included HTTP client.

copy

(copy url & [req])
Like #'request, but sets the :method and :url as appropriate.

delete

(delete url & [req])
Like #'request, but sets the :method and :url as appropriate.

get

(get url & [req])
Like #'request, but sets the :method and :url as appropriate.

get-headers-from-body

(get-headers-from-body body-map)
Given a map of body content, return a map of header-name to header-value.

head

(head url & [req])
Like #'request, but sets the :method and :url as appropriate.

json-decode

(json-decode & args)
Resolve and apply cheshire's json decoding dynamically.

json-encode

(json-encode & args)
Resolve and apply cheshire's json encoding dynamically.

maybe-wrap-entity

(maybe-wrap-entity {:keys [entity-buffering]} entity)
Wrap an HttpEntity in a BufferedHttpEntity if warranted.

move

(move url & [req])
Like #'request, but sets the :method and :url as appropriate.

options

(options url & [req])
Like #'request, but sets the :method and :url as appropriate.

parse-edn

(parse-edn & args)
Resolve and apply tool.reader's EDN parsing.

parse-html

(parse-html & args)
Resolve and apply crouton's HTML parsing.

parse-url

(parse-url url)
Parse a URL string into a map of interesting parts.

patch

(patch url & [req])
Like #'request, but sets the :method and :url as appropriate.

post

(post url & [req])
Like #'request, but sets the :method and :url as appropriate.

put

(put url & [req])
Like #'request, but sets the :method and :url as appropriate.

request

Executes the HTTP request corresponding to the given map and returns
 the response map for corresponding to the resulting HTTP response.

 In addition to the standard Ring request keys, the following keys are also
 recognized:
 * :url
 * :method
 * :query-params
 * :basic-auth
 * :content-type
 * :accept
 * :accept-encoding
 * :as

The following additional behaviors over also automatically enabled:
 * Exceptions are thrown for status codes other than 200-207, 300-303, or 307
 * Gzip and deflate responses are accepted and decompressed
 * Input and output bodies are coerced as required and indicated by the :as
   option.

with-connection-pool

macro

(with-connection-pool opts & body)
Macro to execute the body using a connection manager. Creates a
PoolingClientConnectionManager to use for all requests within the body of
the expression. An option map is allowed to set options for the connection
manager.

The following options are supported:

:timeout - Time that connections are left open before automatically closing
  default: 5
:threads - Maximum number of threads that will be used for connecting
  default: 4
:default-per-route - Maximum number of simultaneous connections per host
  default: 2
:insecure? - Boolean flag to specify allowing insecure HTTPS connections
  default: false

:keystore - keystore file to be used for connection manager
:keystore-pass - keystore password
:trust-store - trust store file to be used for connection manager
:trust-store-pass - trust store password

Note that :insecure? and :keystore/:trust-store options are mutually exclusive

If the value 'nil' is specified or the value is not set, the default value
will be used.

with-middleware

macro

(with-middleware middleware & body)
Perform the body of the macro with a custom middleware list.

It is highly recommended to at least include:
clj-http.client/wrap-url
clj-http.client/wrap-method

Unless you really know what you are doing.

wrap-accept

(wrap-accept client)
Middleware converting the :accept key in a request to application/<type>

wrap-accept-encoding

(wrap-accept-encoding client)
Middleware converting the :accept-encoding option to an acceptable
Accept-Encoding header in the request.

wrap-additional-header-parsing

(wrap-additional-header-parsing client)
Middleware that parses additional http headers from the body of a
web page, adding them into the headers map of the response if any
are found. Only looks at the body if the :decode-body-headers option
is set to a truthy value. Will be silently disabled if crouton is excluded
from clj-http's dependencies.

wrap-basic-auth

(wrap-basic-auth client)
Middleware converting the :basic-auth option into an Authorization header.

wrap-content-type

(wrap-content-type client)
Middleware converting a `:content-type <keyword>` option to the formal
application/<name> format and adding it as a header.

wrap-decompression

(wrap-decompression client)
Middleware handling automatic decompression of responses from web servers. If
:decompress-body is set to false, does not automatically set `Accept-Encoding`
header or decompress body.

wrap-exceptions

(wrap-exceptions client)
Middleware that throws a slingshot exception if the response is not a
regular response. If :throw-entire-message? is set to true, the entire
response is used as the message, instead of just the status number.

wrap-form-params

(wrap-form-params client)
Middleware wrapping the submission or form parameters.

wrap-input-coercion

(wrap-input-coercion client)
Middleware coercing the :body of a request from a number of formats into an
Apache Entity. Currently supports Strings, Files, InputStreams
and byte-arrays.

wrap-lower-case-headers

(wrap-lower-case-headers client)
Middleware lowercasing all headers, as per RFC (case-insensitive) and
Ring spec.

wrap-method

(wrap-method client)
Middleware converting the :method option into the :request-method option

wrap-nested-params

(wrap-nested-params client)
Middleware wrapping nested parameters for query strings.

wrap-oauth

(wrap-oauth client)
Middleware converting the :oauth-token option into an Authorization header.

wrap-output-coercion

(wrap-output-coercion client)
Middleware converting a response body from a byte-array to a different
object. Defaults to a String if no :as key is specified, the
`coerce-response-body` multimethod may be extended to add
additional coercions.

wrap-query-params

(wrap-query-params client)
Middleware converting the :query-params option to a querystring on
the request.

wrap-redirects

(wrap-redirects client)
Middleware that follows redirects in the response. A slingshot exception is
thrown if too many redirects occur. Options

:follow-redirects - default:true, whether to follow redirects
:max-redirects - default:20, maximum number of redirects to follow
:force-redirects - default:false, force redirecting methods to GET requests

In the response:

:redirects-count - number of redirects
:trace-redirects - vector of sites the request was redirected from

wrap-request

(wrap-request request)
Returns a battaries-included HTTP request function coresponding to the given
core client. See client/client.

wrap-request-timing

(wrap-request-timing client)
Middleware that times the request, putting the total time (in milliseconds)
of the request into the :request-time key in the response.

wrap-unknown-host

(wrap-unknown-host client)
Middleware ignoring unknown hosts when the :ignore-unknown-host? option
is set.

wrap-url

(wrap-url client)
Middleware wrapping request URL parsing.

wrap-user-info

(wrap-user-info client)
Middleware converting the :user-info option into a :basic-auth option