This project is a simple web API built with Actix Web and Rhai. The API provides endpoints to perform basic arithmetic operations (multiplication and addition) by evaluating Rhai scripts.
- Multiplication Endpoint: Multiplies two numbers.
- Addition Endpoint: Adds two numbers.
- Rhai Script Evaluation: Uses Rhai scripting engine to execute arithmetic operations.
-
Multiply
- URL:
/multiply/{num1}/{num2} - Method: GET
- Description: Multiplies
num1andnum2and returns the result. - Example:
curl http://127.0.0.1:8080/multiply/3/4
- Response:
12
- Response:
- URL:
-
Add
- URL:
/add/{num1}/{num2} - Method: GET
- Description: Adds
num1andnum2and returns the result. - Example:
curl http://127.0.0.1:8080/add/3/4
- Response:
7
- Response:
- URL:
- Rust (Nightly)
- Actix Web
- Rhai
-
Clone the repository:
https://github.com/b17w1z4rd/actix-web-api-calculator.git cd actix-web-api-calculator -
Add dependencies: Edit
Cargo.tomlto includeactix-webandrhai.[dependencies] actix-web = "4" rhai = "1.8"
-
Create Rhai script files:
-
multiply.rhai:fn multiply() { num1() * num2() } multiply()
-
add.rhai:fn add() { num1() + num2() } add()
-
-
Run the server:
cargo run
-
Access the endpoints:
- Multiply:
http://127.0.0.1:8080/multiply/{num1}/{num2} - Add:
http://127.0.0.1:8080/add/{num1}/{num2}
- Multiply: