---
url: https://haihv.github.io/valifetch/api/index/type-aliases/ValifetchInstance.md
---

# Type Alias: ValifetchInstance

> **ValifetchInstance** = `object`

Defined in: [src/types/instance.ts:282](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L282)

The main valifetch instance type

## Methods

### all()

> **all**<`T`>(`requests`): [`CancellablePromise`](CancellablePromise.md)<{ -readonly \[P in string | number | symbol]: Awaited\<T\[P]> }>

Defined in: [src/types/instance.ts:427](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L427)

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`](CancellablePromise.md)<{ -readonly \[P in string | number | symbol]: Awaited\<T\[P]> }>

#### Example

```ts
const [user, posts] = await api.all([
  api.get('/users/1', { responseSchema: UserSchema }),
  api.get('/posts', { responseSchema: PostsSchema }),
]);
```

***

### allSettled()

> **allSettled**<`T`>(`requests`): [`CancellablePromise`](CancellablePromise.md)<{ -readonly \[P in string | number | symbol]: PromiseSettledResult\<Awaited\<T\[P]>> }>

Defined in: [src/types/instance.ts:450](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L450)

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`](CancellablePromise.md)<{ -readonly \[P in string | number | symbol]: PromiseSettledResult\<Awaited\<T\[P]>> }>

#### Example

```ts
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`](CallableInstance.md)

Defined in: [src/types/instance.ts:467](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L467)

Wrap instance for callable ky-style syntax

#### Returns

[`CallableInstance`](CallableInstance.md)

***

### create()

> **create**(`options?`): `ValifetchInstance`

Defined in: [src/types/instance.ts:457](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L457)

Create new instance with defaults

#### Parameters

##### options?

[`ValifetchInstanceOptions`](ValifetchInstanceOptions.md)

#### Returns

`ValifetchInstance`

***

### delete()

> **delete**<`TData`, `TPath`, `TResponseSchema`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

Defined in: [src/types/instance.ts:368](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L368)

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`](GetOptions.md)<`TPath`, `TResponseSchema`, `TParamsSchema`, `TSearchSchema`>

#### Returns

[`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

***

### extend()

> **extend**(`options`): `ValifetchInstance`

Defined in: [src/types/instance.ts:460](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L460)

Extend current instance with additional options

#### Parameters

##### options

[`ValifetchInstanceOptions`](ValifetchInstanceOptions.md) | ((`parent`) => [`ValifetchInstanceOptions`](ValifetchInstanceOptions.md))

#### Returns

`ValifetchInstance`

***

### get()

> **get**<`TData`, `TPath`, `TResponseSchema`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

Defined in: [src/types/instance.ts:287](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L287)

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`](GetOptions.md)<`TPath`, `TResponseSchema`, `TParamsSchema`, `TSearchSchema`>

#### Returns

[`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

***

### head()

> **head**<`TPath`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`void`>

Defined in: [src/types/instance.ts:383](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L383)

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`](GetOptions.md)<`TPath`, `undefined`, `TParamsSchema`, `TSearchSchema`>, `"responseSchema"` | `"responseType"`>

#### Returns

[`CancellablePromise`](CancellablePromise.md)<`void`>

***

### options()

> **options**<`TData`, `TPath`, `TResponseSchema`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

Defined in: [src/types/instance.ts:399](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L399)

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`](GetOptions.md)<`TPath`, `TResponseSchema`, `TParamsSchema`, `TSearchSchema`>

#### Returns

[`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

***

### patch()

> **patch**<`TData`, `TPath`, `TResponseSchema`, `TBodySchema`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

Defined in: [src/types/instance.ts:346](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L346)

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`](PostOptions.md)<`TPath`, `TResponseSchema`, `TBodySchema`, `TParamsSchema`, `TSearchSchema`>

#### Returns

[`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

***

### post()

> **post**<`TData`, `TPath`, `TResponseSchema`, `TBodySchema`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

Defined in: [src/types/instance.ts:302](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L302)

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`](PostOptions.md)<`TPath`, `TResponseSchema`, `TBodySchema`, `TParamsSchema`, `TSearchSchema`>

#### Returns

[`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

***

### put()

> **put**<`TData`, `TPath`, `TResponseSchema`, `TBodySchema`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

Defined in: [src/types/instance.ts:324](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L324)

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`](PostOptions.md)<`TPath`, `TResponseSchema`, `TBodySchema`, `TParamsSchema`, `TSearchSchema`>

#### Returns

[`CancellablePromise`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>
