Tauri Client

2024-02-02 16:26 更新

Since: 1.0.0

性能

id
idnumber

Defined in: http.ts:303

方法

delete
delete<>(: , : RequestOptions): Promise<ResponseTurlstringoptions?<T>>

发出 DELETE 请求。

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

类型参数

  • T

参数

名字类型
urlstring
options?RequestOptions

Returns: Promise<Response<T>>

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<ResponseTurlstringoptions?<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

参数

名字类型
urlstring
options?RequestOptions

Returns: Promise<Response<T>>

patch
patch<>(: , : RequestOptions): Promise<ResponseTurlstringoptions?<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

参数

名字类型
urlstring
options?RequestOptions

Returns: Promise<Response<T>>

post
post<>(: , : Body, : RequestOptions): Promise<ResponseTurlstringbody?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

参数

名字类型
urlstring
body?Body
options?RequestOptions

Returns: Promise<Response<T>>

put
put<>(: , : Body, : RequestOptions): Promise<ResponseTurlstringbody?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

参数

名字类型
urlstring
body?Body
options?RequestOptions

Returns: Promise<Response<T>>

request
request<>(: HttpOptions): Promise<ResponseToptions<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

参数

名字类型
optionsHttpOptions

返回:Promise<Response<T>>


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号