codecamp

Tauri Client

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


Tauri Body
Tauri Response<T>
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Tauri 指南

Tauri 特性

Tauri 插件

Tauri 应用程序接口

Tauri JavaScript/TypeScript

Tauri 命令行界面

Tauri 进程

Tauri 参考

Tauri WebView 版本

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }