Liking cljdoc? Tell your friends :D

toolnexus.http


http-toolclj/s

(http-tool opts)

Declare a remote endpoint as a Tool (§0.9 / §7).

(http-tool {:name "getUser"
            :description "Fetch a user"
            :input-schema {:type "object"}
            :method :get
            :url "https://api.example.com/users/{id}"
            :headers {"authorization" "Bearer ${API_TOKEN}"}
            :query [:verbose]
            :body "json"           ; "json" (default) | "form" | "raw"
            :timeout-ms 30000
            :result-mode "text"})  ; "text" | "json" | "status+text"

Args are consumed in this order: URL placeholders first, then :query names, and whatever is left becomes the request body (non-GET only).

Declare a remote endpoint as a Tool (§0.9 / §7).

    (http-tool {:name "getUser"
                :description "Fetch a user"
                :input-schema {:type "object"}
                :method :get
                :url "https://api.example.com/users/{id}"
                :headers {"authorization" "Bearer ${API_TOKEN}"}
                :query [:verbose]
                :body "json"           ; "json" (default) | "form" | "raw"
                :timeout-ms 30000
                :result-mode "text"})  ; "text" | "json" | "status+text"

Args are consumed in this order: URL placeholders first, then `:query` names,
and whatever is left becomes the request body (non-GET only).
sourceraw docstring

placeholdersclj/s

(placeholders template)

The {name} placeholders in template, in order of appearance. Scanned by hand rather than with re-seq + a capture group: capture-group semantics are the part of regex most likely to differ between java.util.regex and RE2, and this is plain clojure.core on every host.

The `{name}` placeholders in `template`, in order of appearance. Scanned by
hand rather than with `re-seq` + a capture group: capture-group semantics are
the part of regex most likely to differ between java.util.regex and RE2, and
this is plain clojure.core on every host.
sourceraw docstring

query-stringclj/s

(query-string args names)

The ?-less querystring for the :query names, in DECLARATION order, taking each value from args; nil when nothing matched. Names and values are percent-encoded, and an absent arg contributes no pair at all (rather than an empty one) so an optional parameter is genuinely optional.

Public for the same reason placeholders / substitute / url-encode are: neither host's HTTP server exposes the query portably to the handler (the JVM's URI.getPath strips it, cljgo's :uri keeps it), so an end-to-end test cannot see it. Testing this directly is the only way a :query that is silently dropped fails a test instead of an API call.

The `?`-less querystring for the `:query` names, in DECLARATION order, taking
each value from `args`; nil when nothing matched. Names and values are
percent-encoded, and an absent arg contributes no pair at all (rather than an
empty one) so an optional parameter is genuinely optional.

Public for the same reason `placeholders` / `substitute` / `url-encode` are:
neither host's HTTP server exposes the query portably to the handler (the
JVM's `URI.getPath` strips it, cljgo's `:uri` keeps it), so an end-to-end test
cannot see it. Testing this directly is the only way a `:query` that is
silently dropped fails a test instead of an API call.
sourceraw docstring

substituteclj/s

(substitute template args)

§0.9 — {placeholder} substitution from args.

UNPINNED IN THE SPEC: §0.9 says 'substitution' and never says whether the value is percent-encoded. It is encoded here, because a value with a space otherwise produces a URL the JVM's URI/create rejects outright — i.e. the unencoded reading turns an ordinary argument into a transport failure. Report this so §0.9 pins it for all six ports rather than each port guessing.

A placeholder with no matching arg is left VERBATIM rather than blanked: a half-built URL that 404s is debuggable, a silently mangled one is not.

§0.9 — `{placeholder}` substitution from `args`.

UNPINNED IN THE SPEC: §0.9 says 'substitution' and never says whether the
value is percent-encoded. It is encoded here, because a value with a space
otherwise produces a URL the JVM's `URI/create` rejects outright — i.e. the
unencoded reading turns an ordinary argument into a transport failure. Report
this so §0.9 pins it for all six ports rather than each port guessing.

A placeholder with no matching arg is left VERBATIM rather than blanked: a
half-built URL that 404s is debuggable, a silently mangled one is not.
sourceraw docstring

url-encodeclj/s

(url-encode s)

Percent-encode s (RFC 3986 unreserved set kept, everything else %XX).

Percent-encode `s` (RFC 3986 unreserved set kept, everything else %XX).
sourceraw docstring

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