This API was created for studying purposes. I was interested in learning Rust and started with a simple server to put into practice basic concepts that I learned. The primary goal was to understand how to structure a web service using Rust.
http
GET http://127.0.0.1:8080/
All calculator endpoints accept POST requests with a JSON body: json
{
"a": 5,
"b": 5
}
Available endpoints:
POST /calculator/add
- Performs additionPOST /calculator/sub
- Performs subtractionPOST /calculator/mul
- Performs multiplicationPOST /calculator/div
- Performs divisionPOST /calculator/pow
- Performs power operation
src/
├── main.rs # Application entry point
├── routes.rs # Route configurations
└── calculator/
└── mod.rs # Calculator logic
- Clone the repository
- Use Cargo to build and run the project:
bash
cargo run
- The server will start at
http://127.0.0.1:8080
- Actix Scopes: Help organize routes logically, such as grouping calculator endpoints
- Serde Magic: Automatically converts between Rust structs and JSON
- Handler Pattern: Each endpoint has a dedicated async handler function
- Type Safety: Rust's type system ensures correct data handling
Remember: Just as a Jedi builds their lightsaber, we build our APIs with precision, care, and proper error handling!