Type Alias: ValifetchInstance
ValifetchInstance =
object
Defined in: src/types/instance.ts:282
The main valifetch instance type
Methods
all()
all<
T>(requests):CancellablePromise<{ -readonly [P in string | number | symbol]: Awaited<T[P]> }>
Defined in: src/types/instance.ts:427
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:450
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);
}callable()
callable():
CallableInstance
Defined in: src/types/instance.ts:467
Wrap instance for callable ky-style syntax
Returns
create()
create(
options?):ValifetchInstance
Defined in: src/types/instance.ts:457
Create new instance with defaults
Parameters
options?
Returns
ValifetchInstance
delete()
delete<
TData,TPath,TResponseSchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:368
DELETE request - returns parsed JSON by default
Type Parameters
TData
TData = unknown
Generic type for response (used when no schema provided)
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):ValifetchInstance
Defined in: src/types/instance.ts:460
Extend current instance with additional options
Parameters
options
ValifetchInstanceOptions | ((parent) => ValifetchInstanceOptions)
Returns
ValifetchInstance
get()
get<
TData,TPath,TResponseSchema,TParamsSchema,TSearchSchema>(url,options?):CancellablePromise<ResolveResponseType<TData,TResponseSchema>>
Defined in: src/types/instance.ts:287
GET request - returns parsed JSON by default
Type Parameters
TData
TData = unknown
Generic type for response (used when no schema provided)
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:383
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:399
OPTIONS request - returns parsed JSON by default
Type Parameters
TData
TData = unknown
Generic type for response (used when no schema provided)
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:346
PATCH request - returns parsed JSON by default
Type Parameters
TData
TData = unknown
Generic type for response (used when no schema provided)
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:302
POST request - returns parsed JSON by default
Type Parameters
TData
TData = unknown
Generic type for response (used when no schema provided)
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:324
PUT request - returns parsed JSON by default
Type Parameters
TData
TData = unknown
Generic type for response (used when no schema provided)
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>>