Skip to content

request-url

A wrapper over Obsidian’s requestUrl that fills the gaps plugins keep hand-rolling: an abort signal and a timeout, request bodies beyond string | ArrayBuffer (FormData, URLSearchParams, Blob, typed arrays and streams), an error that carries the status and the body, an up-front protocol check, a streamed response body, and a fetch-compatible adapter that third-party SDKs can take.

requestUrl itself cannot be cancelled: an abort or a timeout settles the returned promise at once, while the underlying request runs to completion and its result is dropped. The streamed variant really cancels on desktop, where it goes through node:http / node:https; that module is imported dynamically, so this one stays cross-platform-loadable. On mobile the streamed variant falls back to requestUrl and delivers the whole body as a single chunk.

Class Description
RequestUrlError The error requestUrlEx and requestUrlStream throw for a status code of 400 or higher.
Interface Description
CreateRequestUrlFetchOptions Options for createRequestUrlFetch.
EncodedRequestUrlRequest The request in the form the transports take: validated, with the body encoded.
RequestUrlErrorConstructorParams Parameters for the RequestUrlError constructor.
RequestUrlExParams Parameters for requestUrlEx.
RequestUrlStreamResponse The response of requestUrlStream.
Function Description
createRequestUrlFetch Creates a fetch-compatible function built on requestUrl, for SDKs that take a custom fetch (OpenAI, LangChain, OAuth clients) and would otherwise hit CORS. Unlike fetch, it never rejects on an HTTP error status: it resolves with a Response carrying that status, exactly as fetch does. It rejects with a TypeError for a URL that is not http: or https:.
encodeRequestUrlRequest Encodes a request for a transport: validates the URL, combines the abort signal with the timeout, encodes the body and settles the content type.
requestUrlEx Requests a URL through requestUrl, with an abort signal, a timeout, richer bodies, a protocol check and a RequestUrlError for an HTTP error status.
requestUrlStream Requests a URL and returns its body as a stream. On desktop the request goes through node:http / node:https, so the body streams as it arrives, an abort really cancels the request, and redirects are followed. On mobile it falls back to requestUrl, and the whole body arrives as a single chunk.
Type Description
EncodeRequestUrlRequestParams Parameters for encodeRequestUrlRequest.
RequestUrlExBody A request body requestUrlEx accepts: everything fetch accepts.
RequestUrlFetch A fetch-compatible function built on requestUrl.
RequestUrlStreamParams Parameters for requestUrlStream.