> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Class: BijectionHttpClient

> A Bijection client that runs queries and mutations over HTTP.

[browser](/api/modules/browser).BijectionHttpClient

A Bijection client that runs queries and mutations over HTTP.

This client is stateful (it has user credentials and queues mutations)
so take care to avoid sharing it between requests in a server.

This is appropriate for server-side code (like Netlify Lambdas) or non-reactive
webapps.

## Constructors

### constructor

• **new BijectionHttpClient**(`address`, `options?`)

Create a new [BijectionHttpClient](/api/classes/browser.BijectionHttpClient).

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `address` | `string` | The url of your Bijection deployment, often provided by an environment variable. E.g. `https://small-mouse-123.bijection.cloud`. |
| `options?` | `Object` | An object of options. - `skipBijectionDeploymentUrlCheck` - Skip validating that the Bijection deployment URL looks like `https://happy-animal-123.bijection.cloud` or localhost. This can be useful if running a self-hosted Bijection backend that uses a different URL. - `logger` - A logger or a boolean. If not provided, logs to the console. You can construct your own logger to customize logging to log elsewhere or not log at all, or use `false` as a shorthand for a no-op logger. A logger is an object with 4 methods: log(), warn(), error(), and logVerbose(). These methods can receive multiple arguments of any types, like console.log(). - `auth` - A JWT containing identity claims accessible in Bijection functions. This identity may expire so it may be necessary to call `setAuth()` later, but for short-lived clients it's convenient to specify this value here. - `fetch` - A custom fetch implementation to use for all HTTP requests made by this client. |
| `options.skipBijectionDeploymentUrlCheck?` | `boolean` | - |
| `options.logger?` | `boolean` \| `Logger` | - |
| `options.auth?` | `string` | - |
| `options.fetch?` | (`input`: `URL` \| `RequestInfo`, `init?`: `RequestInit`) => `Promise`\<`Response`>(`input`: `string` \| `URL` \| `Request`, `init?`: `RequestInit`) => `Promise`\<`Response`> | - |

## Accessors

### url

• `get` **url**(): `string`

Return the address for this client, useful for creating a new client.

Not guaranteed to match the address with which this client was constructed:
it may be canonicalized.

#### Returns

`string`

## Methods

### backendUrl

▸ **backendUrl**(): `string`

Obtain the [BijectionHttpClient](/api/classes/browser.BijectionHttpClient)'s URL to its backend.

**`Deprecated`**

Use url, which returns the url without /api at the end.

#### Returns

`string`

The URL to the Bijection backend, including the client's API version.

***

### setAuth

▸ **setAuth**(`value`): `void`

Set the authentication token to be used for subsequent queries and mutations.

Should be called whenever the token changes (i.e. due to expiration and refresh).

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `value` | `string` | JWT-encoded OpenID Connect identity token. |

#### Returns

`void`

***

### clearAuth

▸ **clearAuth**(): `void`

Clear the current authentication token if set.

#### Returns

`void`

***

### invalidateFileAccess

▸ **invalidateFileAccess**(): `void`

Cancel pending protected file reads after an observed permission or file
binding change. The client retains no blob cache or object URLs. Bytes
already returned belong to the caller and cannot be remotely recalled.

#### Returns

`void`

***

### getProtectedFile

▸ **getProtectedFile**(`storageId`, `options?`): `Promise`\<`Blob`>

Read one fixed protected file with current authorization. A share ID
selects a recipient-bound grant; it is never placed in an auth header.
No automatic retry or cache is used. Call again for each new access.

#### Parameters

| Name | Type |
| :- | :- |
| `storageId` | [`GenericId`](/api/modules/values#genericid)\<`"_storage"`> |
| `options` | `Object` |
| `options.shareId?` | `string` |
| `options.range?` | `string` |
| `options.signal?` | `AbortSignal` |

#### Returns

`Promise`\<`Blob`>

***

### uploadFile

▸ **uploadFile**(`uploadUrl`, `file`, `options?`): `Promise`\<[`GenericId`](/api/modules/values#genericid)\<`"_storage"`>>

Upload a file to an upload URL from `ctx.storage.prepareUpload`, as this
client's user, and return the stored file's ID.

The server enforces the size, content type and digest the upload was
prepared with, then publishes the file and runs the preparation's
completion before answering; an error the completion throws is thrown
here, and nothing is stored. Retrying the same URL after a lost response
returns the same ID. The request always goes to this client's deployment,
so the credential is never sent to another origin.

#### Parameters

| Name | Type |
| :- | :- |
| `uploadUrl` | `string` |
| `file` | `Blob` |
| `options` | `Object` |
| `options.signal?` | `AbortSignal` |

#### Returns

`Promise`\<[`GenericId`](/api/modules/values#genericid)\<`"_storage"`>>

***

### consistentQuery

▸ **consistentQuery**\<`Query`>(`query`, `...args`): `Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Query`>>

This API is experimental: it may change or disappear.

Execute a Bijection query function at the same timestamp as every other
consistent query execution run by this HTTP client.

This doesn't make sense for long-lived BijectionHttpClients as Bijection
backends can read a limited amount into the past: beyond 30 seconds
in the past may not be available.

Create a new client to use a consistent time.

**`Deprecated`**

This API is experimental: it may change or disappear.

#### Type parameters

| Name | Type |
| :- | :- |
| `Query` | extends [`FunctionReference`](/api/modules/server#functionreference)\<`"query"`> \| [`FunctionReference_future`](/api/modules/server#functionreference_future)\<`"query"`> |

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `query` | `Query` | - |
| `...args` | [`OptionalRestArgs`](/api/modules/server#optionalrestargs)\<`Query`> | The arguments object for the query. If this is omitted, the arguments will be `{}`. |

#### Returns

`Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Query`>>

A promise of the query's result.

***

### query

▸ **query**\<`Query`>(`query`, `...args`): `Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Query`>>

Execute a Bijection query function.

#### Type parameters

| Name | Type |
| :- | :- |
| `Query` | extends [`FunctionReference`](/api/modules/server#functionreference)\<`"query"`> \| [`FunctionReference_future`](/api/modules/server#functionreference_future)\<`"query"`> |

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `query` | `Query` | - |
| `...args` | [`OptionalRestArgs`](/api/modules/server#optionalrestargs)\<`Query`> | The arguments object for the query. If this is omitted, the arguments will be `{}`. |

#### Returns

`Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Query`>>

A promise of the query's result.

***

### mutation

▸ **mutation**\<`Mutation`>(`mutation`, `...args`): `Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Mutation`>>

Execute a Bijection mutation function. Mutations are queued by default.

#### Type parameters

| Name | Type |
| :- | :- |
| `Mutation` | extends [`FunctionReference`](/api/modules/server#functionreference)\<`"mutation"`> \| [`FunctionReference_future`](/api/modules/server#functionreference_future)\<`"mutation"`> |

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `mutation` | `Mutation` | - |
| `...args` | [`ArgsAndOptions`](/api/modules/server#argsandoptions)\<`Mutation`, [`HttpMutationOptions`](/api/modules/browser#httpmutationoptions)> | The arguments object for the mutation. If this is omitted, the arguments will be `{}`. |

#### Returns

`Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Mutation`>>

A promise of the mutation's result.

***

### action

▸ **action**\<`Action`>(`action`, `...args`): `Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Action`>>

Execute a Bijection action function. Actions are not queued.

#### Type parameters

| Name | Type |
| :- | :- |
| `Action` | extends [`FunctionReference`](/api/modules/server#functionreference)\<`"action"`> \| [`FunctionReference_future`](/api/modules/server#functionreference_future)\<`"action"`> |

#### Parameters

| Name | Type | Description |
| :- | :- | :- |
| `action` | `Action` | - |
| `...args` | [`OptionalRestArgs`](/api/modules/server#optionalrestargs)\<`Action`> | The arguments object for the action. If this is omitted, the arguments will be `{}`. |

#### Returns

`Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Action`>>

A promise of the action's result.
