Skip to main content

CustomFetch()

type CustomFetch = (url: string, options?: RequestInit & {
timeout?: number;
}) => Promise<CustomFetchResponse>;

Custom fetch function type for providing alternative HTTP implementations. This enables the SDK to work in restrictive environments like Obsidian plugins, browser extensions, Electron apps, React Native, and enterprise environments with specific networking requirements.

Parameters

ParameterTypeDescription
urlstringThe URL to fetch
options?RequestInit & { timeout?: number; }Standard RequestInit options plus optional timeout

Returns

Promise<CustomFetchResponse>

A promise that resolves to a CustomFetchResponse

Example

// Obsidian plugin example
const obsidianFetch: CustomFetch = async (url, options) => {
const response = await requestUrl({ url, method: options?.method, body: options?.body })
return {
ok: response.status >= 200 && response.status < 300,
status: response.status,
statusText: '',
headers: response.headers,
text: async () => response.text,
json: async () => response.json,
}
}