/** * Global default options as {@link Options} that are applied to **all** mande * instances. Always contain an initialized `headers` property with the default * headers: * - Accept: 'application/json' * - 'Content-Type': 'application/json' */ export declare const defaults: _OptionsDefaults; declare type InferArgs = F extends (api: MandeInstance, ...args: infer A) => any ? A : never; /** * Create a Mande instance * * @example * ```js * const users = mande('/api/users') * users.get('2').then(user => { * // do something * }) * ``` * @param baseURL - absolute url * @param passedInstanceOptions - optional options that will be applied to every * other request for this instance */ export declare function mande(baseURL: string, passedInstanceOptions?: OptionsRaw, fetchPolyfill?: Window['fetch']): MandeInstance; /** * Extended Error with the raw `Response` object. */ export declare interface MandeError extends Error { body: T; response: Response; } /** * Object returned by {@link mande} */ export declare interface MandeInstance { /** * Writable options. */ options: Required> & Omit; /** * Sends a GET request to the base url. This is equivalent to calling get with an empty string. * * @example * ```js * const userList = await users.get() * ``` * @param options - optional {@link Options} */ get(options?: Options): MandeResponse; /** * Sends a GET request to the given url. * * @example * ```js * const userProfile = await users.get('2') * ``` * @param url - optional relative url to send the request to * @param options - optional {@link Options} */ get(url: string | number, options?: Options): MandeResponse; /** * Sends a POST request to the base url. This is equivalent to calling post with an empty string. * * @example * ```js * const createdUser = await users.post({ name: 'Eduardo' }) * ``` * @param data - optional body of the request * @param options - optional {@link Options} */ post(data?: any, options?: Options): MandeResponse; /** * Sends a POST request to the given url. * * @example * ```js * const createdUser = await users.post('', { name: 'Eduardo' }) * ``` * @param url - relative url to send the request to * @param data - optional body of the request * @param options - optional {@link Options} */ post(url: string | number, data?: any, options?: Options): MandeResponse; /** * Sends a PUT request to the base url. This is equivalent to calling put with an empty string. * * @example * ```js * users.put({ name: 'Eduardo' }) * ``` * @param data - optional body of the request * @param options - optional {@link Options} */ put(data?: any, options?: Options): MandeResponse; /** * Sends a PUT request to the given url. * * @example * ```js * users.put('2', { name: 'Eduardo' }) * ``` * @param url - relative url to send the request to * @param data - optional body of the request * @param options - optional {@link Options} */ put(url: string | number, data?: any, options?: Options): MandeResponse; /** * Sends a PATCH request to the base url. This is equivalent to calling patch with an empty string. * * @example * ```js * users.patch({ name: 'Eduardo' }) * ``` * @param data - optional body of the request * @param options - optional {@link Options} */ patch(data?: any, options?: Options): MandeResponse; /** * Sends a PATCH request to the given url. * * @example * ```js * users.patch('2', { name: 'Eduardo' }) * ``` */ patch(url: string | number, data?: any, options?: Options): MandeResponse; /** * Sends a DELETE request to the base url. This is equivalent to calling delete with an empty string. * * @example * ```js * users.delete() * ``` * @param options - optional {@link Options} */ delete(options?: Options): MandeResponse; /** * Sends a DELETE request to the given url. * * @example * ```js * users.delete('2') * ``` * @param url - relative url to send the request to * @param options - optional {@link Options} */ delete(url: string | number, options?: Options): MandeResponse; } export declare type MandeResponse = Promise; /** * Creates an Nuxt 2 SSR compatible function that automatically proxies cookies to requests and works transparently on * the server and client (it still requires a fetch polyfill on Node). Note this is only needed if you need to proxy * cookies to the server. * * @example * ```js * import { mande, nuxtWrap } from 'mande' * * const fetchPolyfill = process.server ? require('node-fetch') : fetch * const users = mande(BASE_URL + '/api/users', {}, fetchPolyfill) * * export const getUserById = nuxtWrap(users, (api, id: string) => api.get(id)) * ``` * * @param api - Mande instance to wrap * @param fn - function to be wrapped */ export declare function nuxtWrap any>(api: M, fn: F): (...args: InferArgs) => ReturnType; /** * Allowed options for a request. Extends native `RequestInit`. */ export declare interface Options extends RequestInit { /** * Optional query object. Does not support arrays. Will get stringified */ query?: any; /** * What kind of response is expected. Defaults to `json`. `response` will * return the raw response from `fetch`. */ responseAs?: ResponseAs; /** * Headers sent alongside the request */ headers?: Record; /** * Optional function to stringify the body of the request for POST and PUT requests. Defaults to `JSON.stringify`. */ stringify?: (data: unknown) => string; } /** * Used internally for merged options. * @internal */ export declare type _OptionsDefaults = Options & Pick, 'headers' | 'responseAs' | 'stringify'>; /** * Used internally for merged options * * @internal */ export declare type _OptionsMerged = _OptionsDefaults & Pick, 'method'>; export declare interface OptionsRaw extends Omit, 'headers' | 'signal'> { /** * Headers sent alongside the request. Set any header to null to remove it. */ headers?: Record; /** * AbortSignal can only be passed to requests, not to a mande instance * because it can only be used once. */ signal?: never; } export declare type ResponseAsTypes = 'json' | 'text' | 'response'; export { }