Skip to main content

http.Client

@tauri-apps/api / http / Client

Class: Client

http.Client

Properties​

id​

• id: number

Defined in​

http.ts:246

Methods​

delete​

â–¸ delete<T>(url, options?): Promise<Response<T>>

Makes a DELETE request.

example

import { getClient } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.delete('http://localhost:3003/users/1');

Type parameters​

Name
T

Parameters​

NameTypeDescription
urlstringThe request URL.
options?RequestOptionsThe request options.

Returns​

Promise<Response<T>>

A promise resolving to the response.

Defined in​

http.ts:456


drop​

â–¸ drop(): Promise<void>

Drops the client instance.

example

import { getClient } from '@tauri-apps/api/http';
const client = await getClient();
await client.drop();

Returns​

Promise<void>

Defined in​

http.ts:263


get​

â–¸ get<T>(url, options?): Promise<Response<T>>

Makes a GET request.

example

import { getClient, ResponseType } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.get('http://localhost:3003/users', {
timeout: 30,
// the expected response type
responseType: ResponseType.JSON
});

Type parameters​

Name
T

Parameters​

NameTypeDescription
urlstringThe request URL.
options?RequestOptionsThe request options.

Returns​

Promise<Response<T>>

A promise resolving to the response.

Defined in​

http.ts:343


patch​

â–¸ patch<T>(url, options?): Promise<Response<T>>

Makes a PATCH request.

example

import { getClient, Body } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.patch('http://localhost:3003/users/1', {
body: Body.json({ email: 'contact@tauri.app' })
});

Type parameters​

Name
T

Parameters​

NameTypeDescription
urlstringThe request URL.
options?RequestOptionsThe request options.

Returns​

Promise<Response<T>>

A promise resolving to the response.

Defined in​

http.ts:435


post​

â–¸ post<T>(url, body?, options?): Promise<Response<T>>

Makes a POST request.

example

import { getClient, Body, ResponseType } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.post('http://localhost:3003/users', {
body: Body.json({
name: 'tauri',
password: 'awesome'
}),
// in this case the server returns a simple string
responseType: ResponseType.Text,
});

Type parameters​

Name
T

Parameters​

NameTypeDescription
urlstringThe request URL.
body?BodyThe body of the request.
options?RequestOptionsThe request options.

Returns​

Promise<Response<T>>

A promise resolving to the response.

Defined in​

http.ts:372


put​

â–¸ put<T>(url, body?, options?): Promise<Response<T>>

Makes a PUT request.

example

import { getClient, Body } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.put('http://localhost:3003/users/1', {
body: Body.form({
file: {
file: '/home/tauri/avatar.png',
mime: 'image/png',
fileName: 'avatar.png'
}
})
});

Type parameters​

Name
T

Parameters​

NameTypeDescription
urlstringThe request URL.
body?BodyThe body of the request.
options?RequestOptionsRequest options.

Returns​

Promise<Response<T>>

A promise resolving to the response.

Defined in​

http.ts:407


request​

â–¸ request<T>(options): Promise<Response<T>>

Makes an HTTP request.

example

import { getClient } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.request({
method: 'GET',
url: 'http://localhost:3003/users',
});

Type parameters​

Name
T

Parameters​

NameTypeDescription
optionsHttpOptionsThe request options.

Returns​

Promise<Response<T>>

A promise resolving to the response.

Defined in​

http.ts:288