http.Client
@tauri-apps/api / http / Client
Class: Client
http.Client
Properties​
id​
• id: number
Defined in​
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​
Name | Type | Description |
---|---|---|
url | string | The request URL. |
options? | RequestOptions | The request options. |
Returns​
Promise
<Response
<T
>>
A promise resolving to the response.
Defined in​
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​
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​
Name | Type | Description |
---|---|---|
url | string | The request URL. |
options? | RequestOptions | The request options. |
Returns​
Promise
<Response
<T
>>
A promise resolving to the response.
Defined in​
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​
Name | Type | Description |
---|---|---|
url | string | The request URL. |
options? | RequestOptions | The request options. |
Returns​
Promise
<Response
<T
>>
A promise resolving to the response.
Defined in​
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​
Name | Type | Description |
---|---|---|
url | string | The request URL. |
body? | Body | The body of the request. |
options? | RequestOptions | The request options. |
Returns​
Promise
<Response
<T
>>
A promise resolving to the response.
Defined in​
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​
Name | Type | Description |
---|---|---|
url | string | The request URL. |
body? | Body | The body of the request. |
options? | RequestOptions | Request options. |
Returns​
Promise
<Response
<T
>>
A promise resolving to the response.
Defined in​
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​
Name | Type | Description |
---|---|---|
options | HttpOptions | The request options. |
Returns​
Promise
<Response
<T
>>
A promise resolving to the response.