https://github.com/villaleo/calculator
A lightweight, stateless REST API to perform basic arithmetic operations.
https://github.com/villaleo/calculator
go http rest-api
Last synced: 16 days ago
JSON representation
A lightweight, stateless REST API to perform basic arithmetic operations.
- Host: GitHub
- URL: https://github.com/villaleo/calculator
- Owner: villaleo
- Created: 2025-02-25T22:09:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-27T22:22:40.000Z (about 1 year ago)
- Last Synced: 2025-03-27T23:25:52.536Z (about 1 year ago)
- Topics: go, http, rest-api
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 📟 Calculator API
A lightweight, stateless REST API to perform basic arithmetic operations.
## 🚀 Features
- [x] Perform **addition, subtraction, multiplication, and division** on two numbers.
- [x] Sum an array of numbers.
- [x] Supports floating point numbers.
- [x] Handles errors gracefully.
- [x] Middleware attaches a request ID to each incoming request.
### 👷🏽♂️ Future Features
- [ ] Add in rate limiter to prevent misuse of the API.
- [ ] Add in token authentication to prevent unauthorized users from using the API.
- [ ] Add in a database to keep track of all of the calculations that have taken place.
- [ ] Create an associated http client that can work with the Calculator API.
- [ ] Create a frontend that makes use of the API.
## 📡 Base URL
## 📖 API Endpoints
### Add Two Numbers
**Endpoint:**
```http
POST /add
```
**Request Body:**
```json
{
"x": 10.34,
"y": 45
}
```
**Response:**
```json
{
"interpretation": "10.34 + 45",
"result": 55.34
}
```
### Subtract Two Numbers
**Endpoint:**
```http
POST /subtract
```
**Request Body:**
```json
{
"x": 10.34,
"y": 45
}
```
**Response:**
```json
{
"interpretation": "10.34 - 45",
"result": -34.66
}
```
### Multiply Two Numbers
**Endpoint:**
```http
POST /multiply
```
**Request Body:**
```json
{
"x": 10.34,
"y": 45
}
```
**Response:**
```json
{
"interpretation": "10.34 * 45",
"result": 465.3
}
```
### Divide Two Numbers
**Endpoint:**
```http
POST /divide
```
**Request Body:**
```json
{
"x": 10,
"y": 2
}
```
**Response:**
```json
{
"interpretation": "10 / 2",
"result": 5
}
```
### Sum an Array of Numbers
**Endpoint:**
```http
POST /sum
```
**Request Body:**
```json
{
"numbers": [2, 5, -10, 32.5, -8]
}
```
**Response:**
```json
{
"interpretation": "2 + 5 - 10 + 32.5 - 8",
"result": 21.5
}
```