This microservice provides a suite of arithmetic operations including advanced functions such as exponentiation, square root, and modulus. It ensures robust input validation and supports floating-point numbers.
- Basic Operations: Addition, Subtraction, Multiplication, Division
- Advanced Operations:
- Exponentiation (
base^exp) - Square Root (validates non-negative input)
- Modulus (ensures divisor is non-zero)
- Exponentiation (
- Handles floating-point inputs
- Input validation for safe operation
Before running the project, make sure the following tools are installed:
-
Clone the repository:
git clone https://github.com/Oyeyuvii/sit323-2025-prac4c.git cd sit323-2025-prac4c -
Install dependencies:
npm install
-
Start the service:
node server.js
-
Test an API endpoint:
curl http://localhost:3000/add?n1=5&n2=3
-
Build the Docker image:
docker build -t calculator-microservice . -
Run the container:
docker run -p 3000:3000 calculator-microservice
-
Enable required MicroK8s services:
microk8s enable dns storage -
Apply the Kubernetes deployment:
kubectl apply -f deployment.yaml
| Method | Endpoint | Description |
|---|---|---|
| GET | /add?n1=5&n2=3 | Adds two numbers |
| GET | /subtract?n1=5&n2=3 | Subtracts second number from first |
| GET | /multiply?n1=5&n2=3 | Multiplies two numbers |
| GET | /divide?n1=6&n2=3 | Divides first number by second |
| GET | /power?base=2&exp=3 | Raises base to the exponent |
| GET | /sqrt?n=9 | Computes square root |
| GET | /modulus?n1=10&n2=3 | Computes modulus |
- Ensure all input parameters are valid numbers.
- Division and modulus operations require non-zero denominators.
Yuvraj Singh (s223210987)