π¦ Rust Rhai API
A Rust project demonstrating how to build APIs using Actix Web while executing business logic dynamically with the Rhai scripting engine.
Instead of hardcoding calculations directly into Rust, this project loads logic from external .rhai scripts, making the application more flexible and easier to extend.
βΈ»
β¨ Features
- Build REST APIs using Actix Web
- Execute dynamic logic using Rhai scripts
- Separate application logic from Rust code
- URL parameter handling
- Perform arithmetic operations through API endpoints
- Fast and lightweight backend architecture
βΈ»
π Project Overview
This application receives API requests, extracts input values, executes Rhai scripts, and returns results.
Workflow:
Client Request β Actix Web API β Extract Route Parameters β Pass Values to Rhai Engine β Execute Script File β Return Response
βΈ»
π Tech Stack
- Rust π¦
- Actix Web
- Rhai
- Tokio
βΈ»
π¦ Dependencies
[dependencies] actix-web = "4" rhai = "1" tokio = { version = "1", features = ["full"] }
βΈ»
π» API Endpoints
Multiply Numbers
GET /multiply/{num1}/{num2}
Example:
http://127.0.0.1:8080/multiply/5/6
Response:
30
βΈ»
Add Numbers
GET /add/{num1}/{num2}
Example:
http://127.0.0.1:8080/add/10/20
Response:
30
βΈ»
π» Project Structure
Rust-Rhai-API β βββ src β βββ main.rs β βββ add.rhai β βββ multiply.rhai β βββ Cargo.toml βββ Cargo.lock βββ README.md βββ .gitignore
βΈ»
βΆ Getting Started
Clone the repository:
git clone https://github.com/Hellboy28D/Rust-Rhai-API.git
Move into the project:
cd Rust-Rhai-API
Run the application:
cargo run
Server starts on:
βΈ»
π― Learning Goals
This project helped me understand:
β Building REST APIs with Actix Web β Route parameter extraction β Dynamic scripting using Rhai β Separating logic from application code β Request-response flow in backend systems β Rust ecosystem tooling
βΈ»
π Future Improvements
- Add subtraction and division endpoints
- Add error handling for invalid inputs
- Load scripts dynamically from folders
- Add authentication
- Support custom user scripts
- Docker deployment support
βΈ»
Built with π¦ + APIs + scripting + curiosity