Skip to content

Rust Client

Akram El Assas edited this page Jul 18, 2025 · 3 revisions

Prerequisites

  • Install Rust
  • On Windows Install C++ build tools for Visual Studio and Windows 11 SDK

Client Sample

  1. Create a new Rust project:
cargo new wexflow_client
cd wexflow_client
  1. Edit Cargo.toml:
[package]
name = "wexflow_client"
version = "0.1.0"
edition = "2024"

[dependencies]
reqwest = { version = "0.11", features = ["json", "rustls-tls"] }
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
  1. Create src/main.rs:
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use std::error::Error;

const BASE_URL: &str = "http://localhost:8000/api/v1";
const USERNAME: &str = "admin";
const PASSWORD: &str = "wexflow2018";
const WORKFLOW_ID: u32 = 41;

#[derive(Serialize)]
struct LoginRequest<'a> {
    username: &'a str,
    password: &'a str,
    #[serde(rename = "stayConnected")]
    stay_connected: bool,
}

#[derive(Deserialize)]
struct LoginResponse {
    access_token: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let token = login(USERNAME, PASSWORD).await?;
    let job_id = start_workflow(&token, WORKFLOW_ID).await?;
    println!("Workflow {} started successfully. Job ID: {}", WORKFLOW_ID, job_id);
    Ok(())
}

async fn login(username: &str, password: &str) -> Result<String, Box<dyn Error>> {
    let client = reqwest::Client::new();
    let login_body = LoginRequest {
        username,
        password,
        stay_connected: false,
    };

    let res = client
        .post(format!("{}/login", BASE_URL))
        .json(&login_body)
        .send()
        .await?;

    if res.status() != StatusCode::OK {
        return Err(format!("Login failed: HTTP {} {}", res.status(), res.text().await?).into());
    }

    let login_response: LoginResponse = res.json().await?;
    Ok(login_response.access_token)
}

async fn start_workflow(token: &str, workflow_id: u32) -> Result<String, Box<dyn Error>> {
    let client = reqwest::Client::new();
    let url = format!("{}/start?w={}", BASE_URL, workflow_id);

    let res = client
        .post(&url)
        .bearer_auth(token)
        .send()
        .await?;

    if res.status() != StatusCode::OK {
        return Err(format!("Failed to start workflow: HTTP {} {}", res.status(), res.text().await?).into());
    }

    let job_id = res.text().await?;
    Ok(job_id)
}

To run the client, use the following command:

cargo run
  1. Installing
    1. Windows (.NET 4.8 - Legacy)
      1. Installation Instructions
    2. Windows (.NET 9.0+ - Stable)
      1. Accessing the Admin Panel
      2. Configuration
      3. Running Wexflow as a Windows Service using NSSM
      4. Deleting the Wexflow Windows Service
    3. Linux (.NET 9.0+ - Stable)
      1. Installing the Admin Panel on NGINX
      2. Installing the Admin Panel on Apache2
      3. MongoDB Configuration
      4. Updating Wexflow
    4. macOS (.NET 9.0+ - Stable)
    5. Installing the Admin Panel on a Web Server
      1. .NET 4.8 - Legacy
      2. .NET 9.0+ - Stable
  2. HTTPS/SSL
  3. Screenshots
  4. Docker
  5. Configuration
    1. Wexflow Server
    2. Wexflow.xml
    3. Admin Panel
    4. Authentication
  6. Persistence Providers
  7. Getting Started
  8. Android App
  9. Local Variables
  10. Global Variables
  11. REST Variables
  12. Functions
  13. Cron Scheduling
  14. Command Line Interface (CLI)
  15. REST API Reference
    1. Introduction
    2. JWT Authentication
    3. Sample Clients
      1. C# Client
      2. JavaScript Client
      3. PHP Client
      4. Python Client
      5. Go Client
      6. Rust Client
      7. Ruby Client
      8. Java Client
      9. C++ Client
    4. Security Considerations
    5. Swagger
    6. Workflow Notifications via SSE
      1. C# SSE Client
      2. JavaScript SSE Client
      3. PHP SSE Client
      4. Python SSE Client
      5. Go SSE Client
      6. Rust SSE Client
      7. Ruby SSE Client
      8. Java SSE Client
      9. C++ SSE Client
    7. Endpoints
  16. Samples
    1. Sequential workflows
    2. Execution graph
    3. Flowchart workflows
      1. If
      2. While
      3. Switch
    4. Approval workflows
      1. Simple approval workflow
      2. OnRejected workflow event
      3. YouTube approval workflow
      4. Form submission approval workflow
    5. Workflow events
  17. Logging
  18. Custom Tasks
    1. Introduction
    2. General
      1. Creating a Custom Task
      2. Wexflow Task Class Example
      3. Task Status
      4. Settings
      5. Loading Files
      6. Loading Entities
      7. Need A Starting Point?
    3. Installing Your Custom Task in Wexflow
      1. .NET Framework 4.8 (Legacy Version)
      2. .NET 8.0+ (Stable Version)
      3. Referenced Assemblies
      4. Updating a Custom Task
      5. Using Your Custom Task
    4. Suspend/Resume
    5. Logging
    6. Files
    7. Entities
    8. Shared Memory
    9. Designer Integration
      1. Registering the Task
      2. Adding Settings
  19. Debugging
  20. Built-in Tasks
    1. File system tasks
    2. Encryption tasks
    3. Compression tasks
    4. Iso tasks
    5. Speech tasks
    6. Hashing tasks
    7. Process tasks
    8. Network tasks
    9. XML tasks
    10. SQL tasks
    11. WMI tasks
    12. Image tasks
    13. Audio and video tasks
    14. Email tasks
    15. Workflow tasks
    16. Social media tasks
    17. Waitable tasks
    18. Reporting tasks
    19. Web tasks
    20. Script tasks
    21. JSON and YAML tasks
    22. Entities tasks
    23. Flowchart tasks
    24. Approval tasks
    25. Notification tasks
    26. SMS tasks
  21. Run from Source
Clone this wiki locally