Calling Rust Server Fuctions
With NoApi, calling Rust functions from your frontend is seamless. When you add functions to the src/functions.rs file, NoApi automatically generates TypeScript versions of these functions in the functions.ts file located in your project directory. This allows you to import and use these functions directly in your frontend code.
Heres an example of calling a rust server function:
Rust code( functions.rs )
#![allow(unused)] fn main() { fn get_user(id:u32)->User{ /// } }
Typescript code( your frontend )
import { get_user } from "@functions";
let id: number = 1;
let user: User = await get_user(id);
NoApi handles the conversion between Rust and TypeScript types, ensuring that the data passed between the frontend and backend is type-safe and consistent. This eliminates the need for manual type definitions or additional configuration.
For example, if you define a function in src/functions.rs, you can call it in your React components or other frontend logic as if it were a native TypeScript function.
Why this approach?
This tight integration between Rust and TypeScript simplifies development and reduces the risk of runtime errors.