Skip to content
Tauri

HTTP Client

Make HTTP requests with the http plugin.

Install the http plugin to get started.

Use your project’s package manager to add the dependency:

npm run tauri add http

The http plugin is available in both as an JavaScript API and in Rust as a reqwest re-export.

  1. To keep your app safe, configure allowed scope. Read more on JavaScript API reference.
tauri.conf.json
{
"plugins": {
"http": {
"scope": ["http://my.api.host/*"]
}
}
}
  1. Send a request
import { fetch } from '@tauri-apps/plugin-http';
// Send a GET request
const response = await fetch('http://my.api.host/data.json', {
method: 'GET',
});
console.log(response.status); // e.g. 200
console.log(response.statusText); // e.g. "OK"

In Rust you can utilize the reqwest crate re-exported by the plugin. For more details refer to reqwest docs.

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

© 2024 Tauri Contributors. CC-BY / MIT