HTTP client wrapper for Java's java.net.http.HttpClient.
HTTP client wrapper for Java's java.net.http.HttpClient.
(->body-handler bh)(->body-handler bh file-path)Returns an HttpResponse$BodyHandler.
If a HttpResponse$BodyHandler instance, returns it directly. If a keyword, maps to corresponding HttpResponse$BodyHandlers method: :string -> ofString :bytes -> ofByteArray :input-stream -> ofInputStream :discarding -> discarding :file -> ofFile (second arg may be a Path, File, or String path)
Otherwise, returns ofString.
Returns an HttpResponse$BodyHandler. If a HttpResponse$BodyHandler instance, returns it directly. If a keyword, maps to corresponding HttpResponse$BodyHandlers method: :string -> ofString :bytes -> ofByteArray :input-stream -> ofInputStream :discarding -> discarding :file -> ofFile (second arg may be a Path, File, or String path) Otherwise, returns ofString.
(build &
{:keys [authenticator connect-timeout cookie-handler executor
follow-redirects priority proxy ssl-context ssl-parameters
version]})Builds and returns an HttpClient instance with the specified configuration.
Accepts keyword arguments corresponding to HttpClient.Builder methods. All parameters are optional. Omitted parameters use Java's defaults.
Parameters: :authenticator - java.net.Authenticator instance :connect-timeout - Connection timeout in millis (int) or Duration :cookie-handler - java.net.CookieHandler instance :executor - java.util.concurrent.Executor instance :follow-redirects - Redirect policy keyword: :always, :never, :normal :priority - Integer priority for the client :proxy - java.net.Proxy instance :ssl-context - javax.net.ssl.SSLContext instance :ssl-parameters - javax.net.ssl.SSLParameters instance :version - HTTP version keyword: :HTTP_1_1, :HTTP_2
Returns a java.net.http.HttpClient instance.
Builds and returns an HttpClient instance with the specified configuration. Accepts keyword arguments corresponding to HttpClient.Builder methods. All parameters are optional. Omitted parameters use Java's defaults. Parameters: :authenticator - java.net.Authenticator instance :connect-timeout - Connection timeout in millis (int) or Duration :cookie-handler - java.net.CookieHandler instance :executor - java.util.concurrent.Executor instance :follow-redirects - Redirect policy keyword: :always, :never, :normal :priority - Integer priority for the client :proxy - java.net.Proxy instance :ssl-context - javax.net.ssl.SSLContext instance :ssl-parameters - javax.net.ssl.SSLParameters instance :version - HTTP version keyword: :HTTP_1_1, :HTTP_2 Returns a java.net.http.HttpClient instance.
A pre-built HttpClient instance with default configuration.
Equivalent to calling build with no arguments. Uses Java's default settings for all parameters.
Reuse this instance for multiple requests to avoid overhead.
A pre-built HttpClient instance with default configuration. Equivalent to calling build with no arguments. Uses Java's default settings for all parameters. Reuse this instance for multiple requests to avoid overhead.
(format-redirect redirect)Converts a Clojure keyword or HttpClient$Redirect instance to HttpClient$Redirect enum.
If passed a keyword, converts it to the corresponding enum value. If passed an HttpClient$Redirect instance, returns it unchanged.
Accepted keywords: :always - Always follow redirects :never - Never follow redirects :normal - Follow redirects according to standard behavior
Returns the HttpClient$Redirect enum constant.
Throws IllegalArgumentException if keyword is not recognized.
Converts a Clojure keyword or HttpClient$Redirect instance to HttpClient$Redirect enum. If passed a keyword, converts it to the corresponding enum value. If passed an HttpClient$Redirect instance, returns it unchanged. Accepted keywords: :always - Always follow redirects :never - Never follow redirects :normal - Follow redirects according to standard behavior Returns the HttpClient$Redirect enum constant. Throws IllegalArgumentException if keyword is not recognized.
(format-version version)Converts a Clojure keyword or HttpClient$Version instance to HttpClient$Version enum.
If passed a keyword, converts it to the corresponding HttpClient$Version enum. If passed an HttpClient$Version instance, returns it unchanged.
Accepted keywords: :HTTP_1_1, :HTTP_2
Returns the HttpClient$Version enum constant.
Throws IllegalArgumentException if keyword does not match a valid version.
Converts a Clojure keyword or HttpClient$Version instance to HttpClient$Version enum. If passed a keyword, converts it to the corresponding HttpClient$Version enum. If passed an HttpClient$Version instance, returns it unchanged. Accepted keywords: :HTTP_1_1, :HTTP_2 Returns the HttpClient$Version enum constant. Throws IllegalArgumentException if keyword does not match a valid version.
(send request body-handler)(send client request body-handler)Sends an HTTP request synchronously and returns the response as a Clojure map.
Matches Java signature: HttpClient.send(HttpRequest, BodyHandler)
Arity 2: (send request body-handler) Arity 3: (send client request body-handler)
request is a map with keys: uri, method, headers, body, timeout, version. body-handler is an HttpResponse$BodyHandler (use body-handler helper for keywords).
Returns a map with keys: body, headers, status, uri, version, previous-response, ssl-session.
Throws IOException on network errors, TimeoutException on timeouts.
Sends an HTTP request synchronously and returns the response as a Clojure map. Matches Java signature: HttpClient.send(HttpRequest, BodyHandler) Arity 2: (send request body-handler) Arity 3: (send client request body-handler) request is a map with keys: uri, method, headers, body, timeout, version. body-handler is an HttpResponse$BodyHandler (use body-handler helper for keywords). Returns a map with keys: body, headers, status, uri, version, previous-response, ssl-session. Throws IOException on network errors, TimeoutException on timeouts.
(send-async request body-handler)(send-async client request body-handler)(send-async client request body-handler push-promise-handler)Sends an HTTP request asynchronously and returns a CompletableFuture.
Matches Java signatures: HttpClient.sendAsync(HttpRequest, BodyHandler) HttpClient.sendAsync(HttpRequest, BodyHandler, PushPromiseHandler)
Arity 2: (send-async request body-handler) Arity 3: (send-async client request body-handler) Arity 4: (send-async client request body-handler push-promise-handler)
request is a map with keys: uri, method, headers, body, timeout, version. body-handler is an HttpResponse$BodyHandler. push-promise-handler is an optional function: (fn [initiating-request push-request accept-fn] ...) where accept-fn is a Function<BodyHandler, CompletableFuture<HttpResponse>>.
Returns a CompletableFuture that will complete with the response map.
Throws IOException on network errors, TimeoutException on timeouts.
Sends an HTTP request asynchronously and returns a CompletableFuture. Matches Java signatures: HttpClient.sendAsync(HttpRequest, BodyHandler) HttpClient.sendAsync(HttpRequest, BodyHandler, PushPromiseHandler) Arity 2: (send-async request body-handler) Arity 3: (send-async client request body-handler) Arity 4: (send-async client request body-handler push-promise-handler) request is a map with keys: uri, method, headers, body, timeout, version. body-handler is an HttpResponse$BodyHandler. push-promise-handler is an optional function: (fn [initiating-request push-request accept-fn] ...) where accept-fn is a Function<BodyHandler, CompletableFuture<HttpResponse>>. Returns a CompletableFuture that will complete with the response map. Throws IOException on network errors, TimeoutException on timeouts.
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 |