Type Alias: CallableInstance()
CallableInstance =
CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:96
Callable instance type for ky-style syntax
CallableInstance<
TData,TPath,TResponseSchema,TBodySchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Perform a request, defaulting to GET. Pass method to choose another verb and responseType to change how the body is parsed.
Type Parameters
TData
TData = unknown
TPath
TPath extends string = string
TResponseSchema
TResponseSchema extends GenericSchema | undefined = undefined
TBodySchema
TBodySchema extends GenericSchema | undefined = undefined
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
Omit<RequestInit, "body" | "method" | "window"> & object & object & object & object
Returns
CancellablePromise<ResolveResponseType<TData, TResponseSchema>>
Methods
all()
all<
T>(requests):CancellablePromise<{ -readonly [P in string | number | symbol]: Awaited<T[P]> }>
Defined in: src/types/instance.ts:240
Run multiple requests in parallel and resolve to a tuple of their results, preserving each element's type (sugar over Promise.all). Rejects as soon as any input rejects.
The returned promise is cancellable: .cancel() aborts every input that exposes a .cancel() method (e.g. other valifetch requests); inputs without one are ignored. A rejection does not cancel the remaining requests.
Type Parameters
T
T extends [] | readonly unknown[]
Parameters
requests
T
Returns
CancellablePromise<{ -readonly [P in string | number | symbol]: Awaited<T[P]> }>
Example
const [user, posts] = await api.all([
api.get('/users/1', { responseSchema: UserSchema }),
api.get('/posts', { responseSchema: PostsSchema }),
]);allSettled()
allSettled<
T>(requests):CancellablePromise<{ -readonly [P in string | number | symbol]: PromiseSettledResult<Awaited<T[P]>> }>
Defined in: src/types/instance.ts:263
Run multiple requests in parallel and resolve once all have settled, never rejecting (sugar over Promise.allSettled). Each result is a standard PromiseSettledResult: { status: 'fulfilled', value } or { status: 'rejected', reason } (the reason is typically a ValifetchError).
The returned promise is cancellable: .cancel() aborts every input that exposes a .cancel() method; inputs without one are ignored. A rejection does not cancel the remaining requests.
Type Parameters
T
T extends [] | readonly unknown[]
Parameters
requests
T
Returns
CancellablePromise<{ -readonly [P in string | number | symbol]: PromiseSettledResult<Awaited<T[P]>> }>
Example
const results = await api.allSettled([api.get('/a'), api.get('/b')]);
for (const r of results) {
if (r.status === 'fulfilled') console.log(r.value);
else console.error(r.reason);
}create()
create(
options?):CallableInstance
Defined in: src/types/instance.ts:270
Create new instance with defaults
Parameters
options?
Returns
CallableInstance
delete()
delete<
TData,TPath,TResponseSchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:187
DELETE request
Type Parameters
TData
TData = unknown
TPath
TPath extends string = string
TResponseSchema
TResponseSchema extends GenericSchema | undefined = undefined
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
GetOptions<TPath, TResponseSchema, TParamsSchema, TSearchSchema>
Returns
CancellablePromise<ResolveResponseType<TData, TResponseSchema>>
extend()
extend(
options):CallableInstance
Defined in: src/types/instance.ts:272
Extend current instance with additional options
Parameters
options
ValifetchInstanceOptions | ((parent) => ValifetchInstanceOptions)
Returns
CallableInstance
get()
get<
TData,TPath,TResponseSchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:122
GET request
Type Parameters
TData
TData = unknown
TPath
TPath extends string = string
TResponseSchema
TResponseSchema extends GenericSchema | undefined = undefined
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
GetOptions<TPath, TResponseSchema, TParamsSchema, TSearchSchema>
Returns
CancellablePromise<ResolveResponseType<TData, TResponseSchema>>
head()
head<
TPath,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<void>
Defined in: src/types/instance.ts:201
HEAD request — always resolves to void; the response body is never read, so responseType and responseSchema are not accepted.
Type Parameters
TPath
TPath extends string = string
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
Omit<GetOptions<TPath, undefined, TParamsSchema, TSearchSchema>, "responseSchema" | "responseType">
Returns
CancellablePromise<void>
options()
options<
TData,TPath,TResponseSchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:213
OPTIONS request
Type Parameters
TData
TData = unknown
TPath
TPath extends string = string
TResponseSchema
TResponseSchema extends GenericSchema | undefined = undefined
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
GetOptions<TPath, TResponseSchema, TParamsSchema, TSearchSchema>
Returns
CancellablePromise<ResolveResponseType<TData, TResponseSchema>>
patch()
patch<
TData,TPath,TResponseSchema,TBodySchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:169
PATCH request
Type Parameters
TData
TData = unknown
TPath
TPath extends string = string
TResponseSchema
TResponseSchema extends GenericSchema | undefined = undefined
TBodySchema
TBodySchema extends GenericSchema | undefined = undefined
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
PostOptions<TPath, TResponseSchema, TBodySchema, TParamsSchema, TSearchSchema>
Returns
CancellablePromise<ResolveResponseType<TData, TResponseSchema>>
post()
post<
TData,TPath,TResponseSchema,TBodySchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:133
POST request
Type Parameters
TData
TData = unknown
TPath
TPath extends string = string
TResponseSchema
TResponseSchema extends GenericSchema | undefined = undefined
TBodySchema
TBodySchema extends GenericSchema | undefined = undefined
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
PostOptions<TPath, TResponseSchema, TBodySchema, TParamsSchema, TSearchSchema>
Returns
CancellablePromise<ResolveResponseType<TData, TResponseSchema>>
put()
put<
TData,TPath,TResponseSchema,TBodySchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:151
PUT request
Type Parameters
TData
TData = unknown
TPath
TPath extends string = string
TResponseSchema
TResponseSchema extends GenericSchema | undefined = undefined
TBodySchema
TBodySchema extends GenericSchema | undefined = undefined
TParamsSchema
TParamsSchema extends GenericSchema | undefined = undefined
TSearchSchema
TSearchSchema extends GenericSchema | undefined = undefined
Parameters
url
TPath
options?
PostOptions<TPath, TResponseSchema, TBodySchema, TParamsSchema, TSearchSchema>
Returns
CancellablePromise<ResolveResponseType<TData, TResponseSchema>>