Created
September 12, 2022 02:26
-
-
Save dedSyn4ps3/5703367578339fc8c3440ea8a09fa449 to your computer and use it in GitHub Desktop.
This is a simple example of how a main.rs file may look for a Tauri app that provides the ability for the UI to communicate with the backend to make various requests and actions that should not be handled directly by the frontend.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![cfg_attr( | |
all(not(debug_assertions), target_os = "windows"), | |
windows_subsystem = "windows" | |
)] | |
use reqwest; | |
use std::io::Read; | |
#[tauri::command] | |
fn get_data(address: String, endpoint: String) -> String { | |
let request_url = format!("http://{}/{}", address, endpoint); | |
let mut res = reqwest::blocking::get(&request_url).expect("REQUEST FAILED"); | |
let mut body = String::new(); | |
res.read_to_string(&mut body).expect("Couldn't read into buffer"); | |
return body; | |
} | |
fn main() { | |
tauri::Builder::default() | |
.invoke_handler(tauri::generate_handler![get_data]) | |
.run(tauri::generate_context!()) | |
.expect("error while running tauri application"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment