Generate React Query hooks with qsync
mainThe qsync crate provides a macro-based system to automatically generate React Query hooks for your Rust services. It works by inspecting your service methods and generating corresponding TypeScript hooks for use in your frontend.
Key Requirements & Assumptions:
- React Query Version: Last tested with
"react-query": "^3.39.3". - Data Format: Endpoints must return JSON compatible with
fetch(..).json(). - Routing: The directory structure of your Rust project determines the generated API paths.
- Macro Ordering: When using web frameworks like
actix_web, you must place the#[qsync]attribute above the framework's routing attribute (e.g.,#[get("..")]). This is because Rust evaluates macros from the outermost to the innermost, andqsyncneeds to wrap the method before the framework defines the route.