### Constructing URIs with Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Demonstrates how to build URIs using the verbose ':uri' API for fine-grained and safer construction, including scheme, host, port, path, and query parameters. The example shows a GET request to httpbin.org and parses the JSON response. ```clojure (-> (http/request {:uri {:scheme "https" :host "httpbin.org" :port 443 :path "/get" :query "q=test"}}) :body (json/parse-string true)) ;;=> {:args {:q "test"}, :headers {:Accept "*/*", :Host "httpbin.org", :User-Agent "Java-http-client/11.0.17" :X-Amzn-Trace-Id "Root=1-5e63989e-7bd5b1dba75e951a84d61b6a"}, :origin "46.114.35.45", :url "https://httpbin.org/get?q=test"} ``` -------------------------------- ### Install babashka.http-client dependency Source: https://github.com/babashka/http-client/blob/main/README.md Add `org.babashka/http-client` as a dependency in your `deps.edn` or `bb.edn` file to include the library in your project. ```Clojure org.babashka/http-client {:mvn/version "0.4.22"} ``` -------------------------------- ### Perform a simple HTTP GET request Source: https://github.com/babashka/http-client/blob/main/README.md Demonstrates how to make a basic GET request to a URL and inspect the returned map containing status, body, and headers. ```Clojure (http/get "https://httpstat.us/200") ;;=> {:status 200, :body "200 OK", :headers { ... }} ``` -------------------------------- ### Perform HTTP GET request with Basic Auth Source: https://github.com/babashka/http-client/blob/main/README.md Shows how to include basic authentication credentials (username and password) in a GET request. ```Clojure (:body (http/get "https://postman-echo.com/basic-auth" {:basic-auth ["postman" "password"]})) ;; => "{\"authenticated\":true}" ``` -------------------------------- ### Performing Multipart Requests with Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Explains how to construct and send multipart HTTP requests. It details the options available for each part, including name, content, file name, and content type. An example demonstrates posting a multipart request with text and a file. ```clojure (http/post "https://postman-echo.com/post" {:multipart [{:name "title" :content "My Title"} {:name "Content/type" :content "image/jpeg"} {:name "file" :content (io/file "foo.jpg") :file-name "foobar.jpg"}]}) ``` -------------------------------- ### Managing Exceptions in Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Describes how `babashka.http-client` handles HTTP response status codes. An `ExceptionInfo` is thrown for non-success/redirect codes. The examples show a 404 error being thrown and how to opt out of this behavior by setting ':throw' to false. ```clojure user=> (http/get "https://httpstat.us/404") Execution error (ExceptionInfo) at babashka.http-client.interceptors/fn (interceptors.clj:194). Exceptional status code: 404 ``` ```clojure (:status (http/get "https://httpstat.us/404" {:throw false})) ;;=> 404 ``` -------------------------------- ### babashka.http-client Core API Reference Source: https://github.com/babashka/http-client/blob/main/API.md This section details the core functions within the `babashka.http-client` namespace, including constructors for Java networking components, client configuration, and various HTTP request methods (GET, POST, PUT, DELETE, etc.). ```APIDOC babashka.http-client: ->Authenticator: Constructs a java.net.Authenticator. ->CookieHandler: Constructs a java.net.CookieHandler using java.net.CookieManager. ->Executor: Constructs a java.util.concurrent.Executor. ->ProxySelector: Constructs a java.net.ProxySelector. ->SSLContext: Constructs a javax.net.ssl.SSLContext. ->SSLParameters: Constructs a javax.net.ssl.SSLParameters. client: Construct a custom client. default-client-opts: Options used to create the (implicit) default client. delete: Convenience wrapper for request with method :delete. get: Convenience wrapper for request with method :get. head: Convenience wrapper for request with method :head. patch: Convenience wrapper for request with method :patch. post: Convenience wrapper for request with method :post. put: Convenience wrapper for request with method :put. request: Perform request. ``` -------------------------------- ### Stream HTTP GET response body Source: https://github.com/babashka/http-client/blob/main/README.md Demonstrates how to retrieve the response body as a raw input stream using `:as :stream` for efficient handling of large responses. ```Clojure (:body (http/get "https://github.com/babashka/babashka/raw/master/logo/icon.png" {:as :stream})) ``` -------------------------------- ### Pass custom headers in HTTP GET request Source: https://github.com/babashka/http-client/blob/main/README.md Shows how to include custom headers, such as `Accept: application/json`, in a GET request. Headers can be provided as strings or keywords. ```Clojure (def resp (http/get "https://httpstat.us/200" {:headers {"Accept" "application/json"}})) (json/parse-string (:body resp)) ;;=> {"code" 200, "description" "OK"} ``` ```Clojure {:headers {:content-type "application/json"}} ``` -------------------------------- ### Add query parameters to HTTP GET request Source: https://github.com/babashka/http-client/blob/main/README.md Illustrates how to append single or multiple query parameters to a GET request URL. The response body is parsed to show the received arguments. ```Clojure (-> (http/get "https://postman-echo.com/get" {:query-params {"q" "clojure"}}) :body (json/parse-string true) :args) ;;=> {:q "clojure"} ``` ```Clojure ;; https://postman-echo.com/get?q=clojure&q=curl (-> (http/get "https://postman-echo.com/get" {:query-params {:q ["clojure" "curl"]}}) :body (json/parse-string true) :args) ;;=> {:q ["clojure" "curl"]} ``` -------------------------------- ### Perform HTTP GET request with OAuth token Source: https://github.com/babashka/http-client/blob/main/README.md Illustrates how to add an OAuth bearer token to a GET request for authentication. ```Clojure (:body (http/get "https://httpbin.org/bearer" {:oauth-token "qwertyuiop"})) ;; => "{\n \"authenticated\": true, \n \"token\": \"qwertyuiop\"\n}\n"} ``` -------------------------------- ### Perform HTTP GET Request in Babashka Source: https://github.com/babashka/http-client/blob/main/API.md A convenience wrapper for the `request` function, specifically configured to perform an HTTP GET request. It can be called with just the URI or with additional options to customize the request. ```clojure (get uri) (get uri opts) ``` -------------------------------- ### Creating and Using Custom Babashka HTTP Clients Source: https://github.com/babashka/http-client/blob/main/README.md Explains how to create a custom HTTP client in `babashka.http-client`. It shows how to initialize a client with default options, how to extend these options (e.g., to disable SSL context security), and how to use the custom client in subsequent HTTP requests. ```clojure (def client (http/client http/default-client-opts)) ``` ```clojure (def client (http/client (assoc-in http/default-client-opts [:ssl-context :insecure] true))) ``` ```clojure (http/get "https://clojure.org" {:client client}) ``` -------------------------------- ### Download binary file and save to disk Source: https://github.com/babashka/http-client/blob/main/README.md Shows how to download a binary file by streaming the response body and copying it to a local file. Also demonstrates retrieving the body as a byte array. ```Clojure (io/copy (:body (http/get "https://github.com/babashka/babashka/raw/master/logo/icon.png" {:as :stream})) (io/file "icon.png")) (.length (io/file "icon.png")) ;;=> 7748 ``` -------------------------------- ### Require babashka.http-client and optional namespaces Source: https://github.com/babashka/http-client/blob/main/README.md Import the `babashka.http-client` namespace as `http` for making requests. Optionally, require `clojure.java.io` for file operations and `cheshire.core` for JSON parsing. ```Clojure (require '[babashka.http-client :as http]) (require '[clojure.java.io :as io]) ;; optional (require '[cheshire.core :as json]) ;; optional ``` -------------------------------- ### Running Tests for Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Provides commands for running tests for the Babashka HTTP client, distinguishing between Clojure JVM tests and Babashka native tests. ```Clojure $ bb test:clj $ bb test:bb ``` -------------------------------- ### Construct SSLContext for HTTP Client Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a `javax.net.ssl.SSLContext` for secure communication. It supports extensive configuration via options like `:key-store`, `:key-store-pass`, `:key-store-type`, `:trust-store`, `:trust-store-pass`, `:trust-store-type`, and an `:insecure` flag to accept all server certificates. Note that key and trust store paths can also be set globally via `javax.net.ssl` System properties. ```Clojure (->SSLContext opts) ``` -------------------------------- ### Enabling JVM Logging for Babashka HTTP Client Debugging Source: https://github.com/babashka/http-client/blob/main/README.md Provides instructions on how to enable detailed JVM logging for `java.net.http` to debug HTTP requests. It shows the necessary JVM system property and how to configure it within a `deps.edn` alias for Babashka projects. ```Clojure { ;; REDACTED :aliases { :debug {:jvm-opts [;; enable logging for java.net.http "-Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[:control:data:window:all..],content,ssl,trace,channel"]} }} ``` -------------------------------- ### babashka.http-client.websocket/websocket API Reference Source: https://github.com/babashka/http-client/blob/main/API.md Comprehensive API documentation for the `websocket` function, detailing all available options for configuration, connection timeouts, subprotocols, and event callbacks. ```APIDOC websocket function: Description: Builds java.net.http.Websocket client. Signature: (websocket {:keys [client], :as opts}) Parameters: :uri: The URI to request (required). May be a string or map of :scheme (required), :host (required), :port, :path and :query. :headers: A map of headers for the initial handshake. :client: A client as produced by `client`. If not provided a default client will be used. :connect-timeout: Sets a timeout for establishing a WebSocket connection (in millis). :subprotocols: Sets a request for the given subprotocols. :async: Return CompleteableFuture of websocket. Callbacks: :on-open: [ws] - Called when a WebSocket has been connected. :on-message: [ws data last] - A textual/binary data has been received. :on-ping: [ws data] - A Ping message has been received. :on-pong: [ws data] - A Pong message has been received. :on-close: [ws status reason] - Receives a Close message indicating the WebSocket's input has been closed. :on-error: [ws err] - An error has occurred. ``` -------------------------------- ### Performing Asynchronous HTTP Requests with Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Shows how to make asynchronous HTTP requests using the `:async true` option. The response is a `CompletableFuture` which can be dereferenced to obtain the final response map. ```Clojure (-> (http/get "https://clojure.org" {:async true}) deref :status) ;;=> 200 ``` -------------------------------- ### Accepting Compressed Responses with Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Shows how to configure the HTTP client to accept gzipped or deflated responses by setting the `Accept-Encoding` header. It notes that removing this header might cause requests to fail if the server only serves compressed content. ```clojure (http/get "https://api.stackexchange.com/2.2/sites" {:headers {"Accept-Encoding" ["gzip" "deflate"]}}) ``` -------------------------------- ### Perform HTTP POST request with input stream as body Source: https://github.com/babashka/http-client/blob/main/README.md Shows how to send data from an input stream as the body of a POST request, useful for large files or dynamic content. ```Clojure (:status (http/post "https://postman-echo.com/post" {:body (io/input-stream "README.md")})) ;; => 200 ``` -------------------------------- ### Default Client Options for Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/API.md This constant represents the default configuration options used to initialize the implicit HTTP client in babashka. It provides a baseline for client behavior, which can be explicitly passed to the `client` function for consistent default behavior. ```APIDOC default-client-opts: Options used to create the (implicit) default client. ``` -------------------------------- ### babashka.http-client.websocket API Reference Source: https://github.com/babashka/http-client/blob/main/API.md This section provides documentation for the `babashka.http-client.websocket` namespace, which offers functionalities for building and interacting with WebSocket clients, including methods for sending messages and managing connection closure. ```APIDOC babashka.http-client.websocket: abort!: Closes this WebSocket's input and output abruptly. close!: Initiates an orderly closure of this WebSocket's output by sending a Close message with the given status code and the reason. ping!: Sends a Ping message with bytes from the given buffer. pong!: Sends a Pong message with bytes from the given buffer. send!: Sends a message to the WebSocket. websocket: Builds java.net.http.Websocket client. ``` -------------------------------- ### Perform HTTP POST request with string body Source: https://github.com/babashka/http-client/blob/main/README.md Demonstrates sending a simple string as the body of a POST request and parsing the JSON response. ```Clojure (def resp (http/post "https://postman-echo.com/post" {:body "From Clojure"})) (json/parse-string (:body resp)) ;;=> {"args" {}, "data" "From Clojure", ...} ``` -------------------------------- ### Testing Babashka HTTP Client Interceptors with a Mock Client Source: https://github.com/babashka/http-client/blob/main/README.md Explains how to test interceptors by providing a custom Clojure function as the `:client` option. This allows simulating a Ring-like request/response cycle without making actual HTTP calls, useful for unit testing interceptor logic. ```Clojure (http/get "https://clojure.org" {:client (fn [req] {:body 200})}) ``` -------------------------------- ### Implementing a Custom JSON Interceptor in Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Demonstrates how to create a custom interceptor for the Babashka HTTP client that automatically adds an "application/json" accept header for requests with `:as :json` and decodes the response body as JSON. It shows how to integrate this interceptor into the default chain. ```Clojure (deftest interceptor-test (let [json-interceptor {:name ::json :description "A request with `:as :json` will automatically get the \"application/json\" accept header and the response is decoded as JSON." :request (fn [request] (if (= :json (:as request)) (-> (assoc-in request [:headers :accept] "application/json") ;; Read body as :string ;; Mark request as amenable to json decoding (assoc :as :string ::json true)) request)) :response (fn [response] (if (get-in response [:request ::json]) (update response :body #(json/parse-string % true)) response))} ;; Add json interceptor add beginning of chain ;; It will be the first to see the request and the last to see the response interceptors (cons json-interceptor interceptors/default-interceptors) ] (testing "interceptors on request" (let [resp (http/get "https://httpstat.us/200" {:interceptors interceptors :as :json})] (is (= 200 (-> resp :body ;; response as JSON :code))))))) ``` -------------------------------- ### Construct Authenticator for HTTP Client Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a `java.net.Authenticator` instance. This function takes options for user credentials, specifically `:user` for the username and `:pass` for the password, to configure the authenticator for HTTP client requests. ```Clojure (->Authenticator opts) ``` -------------------------------- ### Configure Custom HTTP Client in Babashka Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a custom HTTP client instance. This function allows fine-grained control over client behavior, including redirect handling, timeouts, SSL, proxy settings, and HTTP version. It returns a map containing the `java.net.http.HttpClient` instance, which can then be used for making requests. ```APIDOC client(opts) Constructs a custom client. To get the same behavior as the (implicit) default client, pass default-client-opts. Parameters: opts: Map of options for client configuration. :follow-redirects - Redirect handling: :never, :always, or :normal. :connect-timeout - Connection timeout in milliseconds. :request - Default request options for client-made requests. :executor - java.util.concurrent.Executor or map of options for ->Executor. :ssl-context - javax.net.ssl.SSLContext or map of options for ->SSLContext. :ssl-parameters - javax.net.ssl.SSLParameters or map of options for ->SSLParameters. :proxy - java.net.ProxySelector or map of options for ->ProxySelector. :authenticator - java.net.Authenticator or map of options for ->Authenticator. :cookie-handler - java.net.CookieHandler or map of options for ->CookieHandler. :version - HTTP version: :http1.1 or :http2 (default: :http2). :priority - Priority for HTTP2 requests (integer 1-256). Returns: Map :client - A java.net.http.HttpClient instance. Usage: The returned map can be passed to the 'request' function via the ':client' key. ``` -------------------------------- ### Perform HTTP POST request with JSON body Source: https://github.com/babashka/http-client/blob/main/README.md Shows how to send a JSON object as the request body by setting the `Content-Type` header and encoding the data. ```Clojure (def resp (http/post "https://postman-echo.com/post" {:headers {:content-type "application/json"} :body (json/encode {:a 1 :b "2"})})) (:data (json/parse-string (:body resp) true)) ;;=> {:a 1, :b "2"} ``` -------------------------------- ### Construct CookieHandler for HTTP Client Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a `java.net.CookieHandler` using `java.net.CookieManager`. It accepts an optional `:store` for a `java.net.CookieStore` implementation and a `:policy` which can be a `java.net.CookiePolicy` object or keywords like `:accept-all`, `:accept-none`, or `:original-server` to define cookie handling behavior. ```Clojure (->CookieHandler opts) ``` -------------------------------- ### Perform HTTP POST request with file as body Source: https://github.com/babashka/http-client/blob/main/README.md Illustrates sending the content of a local file as the body of a POST request using `clojure.java.io/file`. ```Clojure (:status (http/post "https://postman-echo.com/post" {:body (io/file "README.md")})) ;; => 200 ``` -------------------------------- ### Construct SSLParameters for HTTP Client Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a `javax.net.ssl.SSLParameters` object. This function allows specification of security parameters for SSL/TLS connections, including `:ciphers` (a list of cipher suite names) and `:protocols` (a list of protocol names) to control the cryptographic algorithms and versions used. ```Clojure (->SSLParameters opts) ``` -------------------------------- ### Perform HTTP POST request with form parameters Source: https://github.com/babashka/http-client/blob/main/README.md Demonstrates sending data as URL-encoded form parameters in a POST request. ```Clojure (:status (http/post "https://postman-echo.com/post" {:form-params {"name" "Michiel"}})) ;; => 200 ``` -------------------------------- ### Construct ProxySelector for HTTP Client Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a `java.net.ProxySelector`. This function allows configuration of a proxy server using `:host` (string) for the proxy's hostname and `:port` (long) for its port number, enabling HTTP client requests to be routed through a proxy. ```Clojure (->ProxySelector opts) ``` -------------------------------- ### Perform HTTP HEAD Request in Babashka Source: https://github.com/babashka/http-client/blob/main/API.md A convenience wrapper for the `request` function, specifically configured to perform an HTTP HEAD request. It can be called with just the URI or with additional options to customize the request. ```clojure (head uri) (head uri opts) ``` -------------------------------- ### babashka.http-client/request API Reference Source: https://github.com/babashka/http-client/blob/main/API.md Perform an HTTP request with a wide range of configurable options. The function returns a map containing at least the `:body` and `:status` of the response. It supports various request methods, authentication, asynchronous operations, and custom interceptor chains. ```APIDOC (request opts) Perform request. Returns map with at least :body, :status Options: * :uri - the uri to request (required). May be a string or map of :scheme (required), :host (required), :port, :path and :query * :headers - a map of headers * :method - the request method: :get, :post, :head, :delete, :patch or :put * :interceptors - custom interceptor chain * :client - a client as produced by client or a clojure function. If not provided a default client will be used. When providing :client with a a clojure function, it will be called with the Clojure representation of the request which can be useful for testing. * :query-params - a map of query params. The values can be a list to send multiple params with the same key. * :form-params - a map of form params to send in the request body. * :body - a file, inputstream or string to send as the request body. * :basic-auth - a sequence of user password or map with :user :pass used for basic auth. * :oauth-token - a string token used for bearer auth. * :async - perform request asynchronously. The response will be a CompletableFuture of the response map. * :async-then - a function that is called on the async result if successful * :async-catch - a function that is called on the async result if exceptional * :timeout - request timeout in milliseconds * :throw - throw on exceptional status codes, all other than #{200 201 202 203 204 205 206 207 300 301 302 303 304 307} * :version - the HTTP version: :http1.1 or :http2 (default: :http2). ``` -------------------------------- ### Perform HTTP POST Request in Babashka Source: https://github.com/babashka/http-client/blob/main/API.md A convenience wrapper for the `request` function, specifically configured to perform an HTTP POST request. It can be called with just the URI or with additional options to customize the request. ```clojure (post uri) (post uri opts) ``` -------------------------------- ### babashka.http-client.interceptors/uri-with-query Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a URI with a new query, avoiding automatic encoding issues encountered with standard URI constructors. This is useful for precise control over URI encoding. ```Clojure (uri-with-query uri new-query) ``` -------------------------------- ### Handling Request Timeouts with Async Deref in Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Demonstrates an alternative method for handling request timeouts using the `:async true` option combined with `deref` and a timeout value. This allows specifying a default value to return if the request does not complete within the given time. ```Clojure (let [resp (http/get "https://httpstat.us/200?sleep=5000" {:async true})] (deref resp 1000 ::too-late)) ;;=> :user/too-late ``` -------------------------------- ### Handling Redirects with Babashka HTTP Client Source: https://github.com/babashka/http-client/blob/main/README.md Illustrates how to configure redirect behavior for HTTP requests. By default, the client follows redirects. This snippet shows how to explicitly disable (':never') or enable (':always') redirect following using a custom client configuration. ```clojure (:status (http/get "https://httpstat.us/302" {:client (http/client {:follow-redirects :never})})) ;; => 302 (:status (http/get "https://httpstat.us/302" {:client (http/client {:follow-redirects :always})})) ;; => 200 ``` -------------------------------- ### babashka.http-client.interceptors/query-params Source: https://github.com/babashka/http-client/blob/main/API.md Encodes the `:query-params` map from the request and appends it to the `:uri`. ```APIDOC query-params ``` -------------------------------- ### Perform HTTP PUT Request in Babashka Source: https://github.com/babashka/http-client/blob/main/API.md A convenience wrapper for the `request` function, specifically configured to perform an HTTP PUT request. It can be called with just the URL or with additional options to customize the request. ```clojure (put url) (put url opts) ``` -------------------------------- ### Construct Executor for HTTP Client Source: https://github.com/babashka/http-client/blob/main/API.md Constructs a `java.util.concurrent.Executor`. The primary option is `:threads`, which, when specified, configures a `ThreadPoolExecutor` with the given number of threads for managing concurrent tasks. ```Clojure (->Executor opts) ``` -------------------------------- ### Clojure websocket Function Signature Source: https://github.com/babashka/http-client/blob/main/API.md The basic function signature for creating a WebSocket client in Clojure using `babashka.http-client`. ```clojure (websocket {:keys [client], :as opts}) ``` -------------------------------- ### babashka.http-client.interceptors/oauth-token Source: https://github.com/babashka/http-client/blob/main/API.md Adds an `:authorization` header to the request based on the `:oauth-token` string provided in the request. ```APIDOC oauth-token ``` -------------------------------- ### babashka.http-client.websocket/abort! Source: https://github.com/babashka/http-client/blob/main/API.md Abruptly closes both the input and output streams of the WebSocket connection. ```Clojure (abort! ws) ``` -------------------------------- ### Modifying an Existing Babashka HTTP Client Interceptor Source: https://github.com/babashka/http-client/blob/main/README.md Illustrates how to override or modify a default interceptor, specifically changing the `throw-on-exceptional-status-code` interceptor to prevent it from throwing an exception on a `404` status code. It shows how to replace an interceptor within the default chain. ```Clojure (require '[babashka.http-client :as http] '[babashka.http-client.interceptors :as i]) (def unexceptional-statuses (conj #{200 201 202 203 204 205 206 207 300 301 302 303 304 307} ;; we also don't throw on 404 404)) (def my-throw-on-exceptional-status-code "Response: throw on exceptional status codes" {:name ::throw-on-exceptional-status-code :response (fn [resp] (if-let [status (:status resp)] (if (or (false? (some-> resp :request :throw)) (contains? unexceptional-statuses status)) resp (throw (ex-info (str "Exceptional status code: " status) resp))) resp))}) (def my-interceptors (mapv (fn [i] (if (= ::i/throw-on-exceptional-status-code (:name i)) my-throw-on-exceptional-status-code i)) i/default-interceptors)) (def my-response (http/get "https://postman-echo.com/get/404" {:interceptors my-interceptors})) (prn (:status my-response)) ;; 404 ``` -------------------------------- ### babashka.http-client.websocket/pong! Source: https://github.com/babashka/http-client/blob/main/API.md Sends a Pong message over the WebSocket connection using bytes from the provided buffer. ```Clojure (pong! ws data) ``` -------------------------------- ### babashka.http-client.interceptors API Reference Source: https://github.com/babashka/http-client/blob/main/API.md This section outlines the interceptor functions available in `babashka.http-client.interceptors`. Interceptors allow for modifying requests before they are sent and responses after they are received, handling common tasks like header manipulation, body encoding/decoding, and error handling. ```APIDOC babashka.http-client.interceptors: accept-header: Request: adds :accept header. basic-auth: Request: adds :authorization header based on :basic-auth (a map of :user and :pass) in request. construct-uri: Request: construct uri from map. decode-body: Response: based on the value of :as in request, decodes as :string, :stream or :bytes. decompress-body: Response: decompresses body based on "content-encoding" header. default-interceptors: Default interceptor chain. form-params: Request: encodes :form-params map and adds :body. multipart: Adds appropriate body and header if making a multipart request. oauth-token: Request: adds :authorization header based on :oauth-token (a string token) in request. query-params: Request: encodes :query-params map and appends to :uri. throw-on-exceptional-status-code: Response: throw on exceptional status codes. unexceptional-statuses: (No description provided in source) uri-with-query: We can't use the URI constructor because it encodes all arguments for us. ``` -------------------------------- ### babashka.http-client.websocket/send! Source: https://github.com/babashka/http-client/blob/main/API.md Sends a message to the WebSocket. The `data` can be a CharSequence (e.g., string), byte array, or ByteBuffer. An optional `:last` option can be set to `false` if it's not the final message in a sequence. ```Clojure (send! ws data) (send! ws data opts) ``` -------------------------------- ### babashka.http-client.websocket/ping! Source: https://github.com/babashka/http-client/blob/main/API.md Sends a Ping message over the WebSocket connection using bytes from the provided buffer. ```Clojure (ping! ws data) ``` -------------------------------- ### babashka.http-client.interceptors/multipart Interceptor Source: https://github.com/babashka/http-client/blob/main/API.md A request interceptor that prepares the request for multipart form data. It adds the appropriate body content and sets the necessary headers for multipart requests. ```APIDOC Adds appropriate body and header if making a multipart request. ``` -------------------------------- ### babashka.http-client.interceptors/basic-auth Interceptor Source: https://github.com/babashka/http-client/blob/main/API.md A request interceptor that adds the `:authorization` header for basic authentication. It uses the `:basic-auth` option (a map with `:user` and `:pass`) from the request to construct the header. ```APIDOC Request: adds `:authorization` header based on `:basic-auth` (a map of `:user` and `:pass`) in request. ``` -------------------------------- ### Perform HTTP PATCH Request in Babashka Source: https://github.com/babashka/http-client/blob/main/API.md A convenience wrapper for the `request` function, specifically configured to perform an HTTP PATCH request. It can be called with just the URL or with additional options to customize the request. ```clojure (patch url) (patch url opts) ``` -------------------------------- ### babashka.http-client.interceptors/default-interceptors Interceptor Chain Source: https://github.com/babashka/http-client/blob/main/API.md Represents the default interceptor chain used by the HTTP client. Interceptors in this chain are executed in order for requests and in reverse order for responses. ```APIDOC Default interceptor chain. Interceptors are called in order for request and in reverse order for response. ``` -------------------------------- ### babashka.http-client.interceptors/construct-uri Interceptor Source: https://github.com/babashka/http-client/blob/main/API.md A request interceptor responsible for constructing the URI from a map representation provided in the request options. ```APIDOC Request: construct uri from map ``` -------------------------------- ### babashka.http-client.interceptors/decompress-body Interceptor Source: https://github.com/babashka/http-client/blob/main/API.md A response interceptor that decompresses the response body. It inspects the "content-encoding" header and supports `gzip` and `deflate` compression methods. ```APIDOC Response: decompresses body based on "content-encoding" header. Valid values: `gzip` and `deflate`. ``` -------------------------------- ### Perform HTTP DELETE Request in Babashka Source: https://github.com/babashka/http-client/blob/main/API.md A convenience wrapper for the `request` function, specifically configured to perform an HTTP DELETE request. It can be called with just the URI or with additional options to customize the request. ```clojure (delete uri) (delete uri opts) ``` -------------------------------- ### babashka.http-client.interceptors/unexceptional-statuses Source: https://github.com/babashka/http-client/blob/main/API.md This interceptor likely defines or handles statuses that are considered non-exceptional, preventing them from triggering an error. ```APIDOC unexceptional-statuses ``` -------------------------------- ### babashka.http-client.websocket/close! Source: https://github.com/babashka/http-client/blob/main/API.md Initiates an orderly closure of the WebSocket connection's output by sending a Close message. It can optionally include a status code and a reason for closure. ```Clojure (close! ws) (close! ws status-code reason) ``` -------------------------------- ### babashka.http-client.interceptors/accept-header Interceptor Source: https://github.com/babashka/http-client/blob/main/API.md A request interceptor that automatically adds the `:accept` header to the outgoing request. Currently, it only supports setting the accept type to `:json`. ```APIDOC Request: adds `:accept` header. Only supported value is `:json`. ``` -------------------------------- ### babashka.http-client.interceptors/decode-body Interceptor Source: https://github.com/babashka/http-client/blob/main/API.md A response interceptor that decodes the response body. The decoding format is determined by the `:as` option in the original request, supporting `:string`, `:stream`, or `:bytes`. Defaults to `:string` if not specified. ```APIDOC Response: based on the value of `:as` in request, decodes as `:string`, `:stream` or `:bytes`. Defaults to `:string`. ``` -------------------------------- ### babashka.http-client.interceptors/throw-on-exceptional-status-code Source: https://github.com/babashka/http-client/blob/main/API.md An interceptor that throws an exception when the HTTP response status code indicates an error. ```APIDOC throw-on-exceptional-status-code ``` -------------------------------- ### babashka.http-client.interceptors/form-params Interceptor Source: https://github.com/babashka/http-client/blob/main/API.md A request interceptor that encodes the `:form-params` map and adds it to the request body, typically for `application/x-www-form-urlencoded` content types. ```APIDOC Request: encodes `:form-params` map and adds `:body`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.