Tauri Client
Since: 1.0.0
性能
id
id:number
Defined in: http.ts:303
方法
delete
delete<>(: , :RequestOptions
):Promise
<Response
T
url
string
options?
<T
>>
发出 DELETE 请求。
例
import { getClient } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.delete('http://localhost:3003/users/1');
类型参数
- T
参数
名字 | 类型 |
---|---|
url | string |
options? | RequestOptions |
drop
drop():Promise
<void
>
删除客户端实例。
例
import { getClient } from '@tauri-apps/api/http';
const client = await getClient();
await client.drop();
Returns: Promise
<void
>
get
get<>(: , :RequestOptions
):Promise
<Response
T
url
string
options?
<T
>>
发出 GET 请求。
例
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
});
类型参数
- T
参数
名字 | 类型 |
---|---|
url | string |
options? | RequestOptions |
patch
patch<>(: , :RequestOptions
):Promise
<Response
T
url
string
options?
<T
>>
发出 PATCH 请求。
例
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' })
});
类型参数
- T
参数
名字 | 类型 |
---|---|
url | string |
options? | RequestOptions |
post
post<>(: , :Body
, :RequestOptions
):Promise
<Response
T
url
string
body?
options?
<T
>>
发出 POST 请求。
例
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,
});
类型参数
- T
参数
名字 | 类型 |
---|---|
url | string |
body? | Body |
options? | RequestOptions |
put
put<>(: , :Body
, :RequestOptions
):Promise
<Response
T
url
string
body?
options?
<T
>>
发出 PUT 请求。
例
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'
}
})
});
类型参数
- T
参数
名字 | 类型 |
---|---|
url | string |
body? | Body |
options? | RequestOptions |
request
request<>(:HttpOptions
):Promise
<Response
T
options
<T
>>
发出 HTTP 请求。
例
import { getClient } from '@tauri-apps/api/http';
const client = await getClient();
const response = await client.request({
method: 'GET',
url: 'http://localhost:3003/users',
});
类型参数
- T
参数
名字 | 类型 |
---|---|
options | HttpOptions |