HTTP クライアント
http プラグインを使用して HTTP リクエストを行います。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | ||
| ios |
http プラグインをインストールして開始します。
プロジェクトのパッケージマネージャーを使用して依存関係を追加します:
npm run tauri add httpyarn run tauri add httppnpm tauri add httpdeno task tauri add httpbun tauri add httpcargo tauri add http-
src-tauriフォルダーで次のコマンドを実行して、Cargo.tomlのプロジェクトの依存関係にプラグインを追加します:cargo add tauri-plugin-http -
lib.rsを変更してプラグインを初期化します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_http::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
JavaScript で http リクエストを行う場合は、npm パッケージもインストールします:
npm install @tauri-apps/plugin-httpyarn add @tauri-apps/plugin-httppnpm add @tauri-apps/plugin-httpdeno add npm:@tauri-apps/plugin-httpbun add @tauri-apps/plugin-http
HTTP プラグインは、reqwest の再エクスポートとして Rust で、また JavaScript で使用できます。
-
許可された URL を構成する
src-tauri/capabilities/default.json {"permissions": [{"identifier": "http:default","allow": [{ "url": "https://*.tauri.app" }],"deny": [{ "url": "https://private.tauri.app" }]}]}詳細については、権限の概要のドキュメントを参照してください。
-
リクエストを送信する
fetchメソッドは、可能な限りfetchWeb API に近づけ、準拠しようとします。import { fetch } from '@tauri-apps/plugin-http';// GET リクエストを送信するconst response = await fetch('http://test.tauri.app/data.json', {method: 'GET',});console.log(response.status); // 例: 200console.log(response.statusText); // 例: "OK"
Rust では、プラグインによって再エクスポートされた reqwest クレートを利用できます。詳細については、reqwest のドキュメントを参照してください。
use tauri_plugin_http::reqwest;
let res = reqwest::get("http://my.api.host/data.json").await;println!("{:?}", res.status()); // 例: 200println!("{:?}", res.text().await); // 例: Ok("{ Content }")Default Permission
This permission set configures what kind of fetch operations are available from the http plugin.
This enables all fetch operations but does not allow explicitly any origins to be fetched. This needs to be manually configured before usage.
Granted Permissions
All fetch operations are enabled.
This default permission set includes the following:
allow-fetchallow-fetch-cancelallow-fetch-read-bodyallow-fetch-send
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the fetch command without any pre-configured scope. |
|
|
Denies the fetch command without any pre-configured scope. |
|
|
Enables the fetch_cancel command without any pre-configured scope. |
|
|
Denies the fetch_cancel command without any pre-configured scope. |
|
|
Enables the fetch_read_body command without any pre-configured scope. |
|
|
Denies the fetch_read_body command without any pre-configured scope. |
|
|
Enables the fetch_send command without any pre-configured scope. |
|
|
Denies the fetch_send command without any pre-configured scope. |
© 2025 Tauri Contributors. CC-BY / MIT