Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ¦€ 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:

http://127.0.0.1:8080

βΈ»

🎯 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages