コンテンツにスキップ
Tauri

HTTP Client(HTTP クライアント)

《訳注》

Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。

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

「HTTP」プラグインは、JavaScrip と reqwest の再エクスポート(re-export)としての Rust の両方で利用可能です。

  1. 許可されたURLを設定します

    src-tauri/capabilities/default.json
    {
    "permissions": [
    {
    "identifier": "http:default",
    "allow": [{ "url": "https://*.tauri.app" }],
    "deny": [{ "url": "https://private.tauri.app" }]
    }
    ]
    }

    詳細については、アクセス権の概要のドキュメントをご覧ください。

  2. リクエストの送信

    fetch」メソッドは、fetch Web 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); // たとえば 200
    console.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()); // e.g. 200
println!("{:?}", res.text().await); // e.g 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-fetch
  • allow-fetch-cancel
  • allow-fetch-send
  • allow-fetch-read-body
  • allow-fetch-cancel-body

Permission Table

Identifier Description

http:allow-fetch

Enables the fetch command without any pre-configured scope.

http:deny-fetch

Denies the fetch command without any pre-configured scope.

http:allow-fetch-cancel

Enables the fetch_cancel command without any pre-configured scope.

http:deny-fetch-cancel

Denies the fetch_cancel command without any pre-configured scope.

http:allow-fetch-cancel-body

Enables the fetch_cancel_body command without any pre-configured scope.

http:deny-fetch-cancel-body

Denies the fetch_cancel_body command without any pre-configured scope.

http:allow-fetch-read-body

Enables the fetch_read_body command without any pre-configured scope.

http:deny-fetch-read-body

Denies the fetch_read_body command without any pre-configured scope.

http:allow-fetch-send

Enables the fetch_send command without any pre-configured scope.

http:deny-fetch-send

Denies the fetch_send command without any pre-configured scope.

【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】


© 2025 Tauri Contributors. CC-BY / MIT