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

# Type Alias: CallableInstance()

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

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

Callable instance type for ky-style syntax

> **CallableInstance**<`TData`, `TPath`, `TResponseSchema`, `TBodySchema`, `TParamsSchema`, `TSearchSchema`>(`url`, `options?`): [`CancellablePromise`](CancellablePromise.md)<`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`](CancellablePromise.md)<`ResolveResponseType`<`TData`, `TResponseSchema`>>

## Methods

### all()

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

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

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:263](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L263)

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);
}
```

***

### create()

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

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

Create new instance with defaults

#### Parameters

##### options?

[`ValifetchInstanceOptions`](ValifetchInstanceOptions.md)

#### Returns

`CallableInstance`

***

### delete()

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

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

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

#### Returns

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

***

### extend()

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

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

Extend current instance with additional options

#### Parameters

##### options

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

#### Returns

`CallableInstance`

***

### get()

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

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

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`](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:201](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L201)

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:213](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L213)

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`](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:169](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L169)

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`](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:133](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L133)

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`](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:151](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/types/instance.ts#L151)

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

#### Returns

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