Tauri Client

2024-02-02 16:26 更新

Since: 1.0.0

性能

id?
idnumber

Defined in: http.ts:303

方法

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

發(fā)出 DELETE 請(qǐng)求。

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

類型參數(shù)

  • T

參數(shù)

名字類型
urlstring
options?RequestOptions

Returns: Promise<Response<T>>

drop?
drop(): Promise<void>

刪除客戶端實(shí)例。

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

Returns: Promise<void>

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

發(fā)出 GET 請(qǐng)求。

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
});

類型參數(shù)

  • T

參數(shù)

名字類型
urlstring
options?RequestOptions

Returns: Promise<Response<T>>

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

發(fā)出 PATCH 請(qǐng)求。

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' })
});

類型參數(shù)

  • T

參數(shù)

名字類型
urlstring
options?RequestOptions

Returns: Promise<Response<T>>

post?
post<>(: , : Body, : RequestOptions): Promise<ResponseTurlstringbody?options?<T>>

發(fā)出 POST 請(qǐng)求。

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,
});

類型參數(shù)

  • T

參數(shù)

名字類型
urlstring
body?Body
options?RequestOptions

Returns: Promise<Response<T>>

put?
put<>(: , : Body, : RequestOptions): Promise<ResponseTurlstringbody?options?<T>>

發(fā)出 PUT 請(qǐng)求。

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'
}
})
});

類型參數(shù)

  • T

參數(shù)

名字類型
urlstring
body?Body
options?RequestOptions

Returns: Promise<Response<T>>

request?
request<>(: HttpOptions): Promise<ResponseToptions<T>>

發(fā)出 HTTP 請(qǐng)求。

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

類型參數(shù)

  • T

參數(shù)

名字類型
optionsHttpOptions

返回:Promise<Response<T>>


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)