A REST API implementation of the classic FizzBuzz algorithm built with Express and TypeScript.
For each number in a given range:
- Divisible by 3 →
"Fizz" - Divisible by 5 →
"Buzz" - Divisible by both 3 and 5 →
"FizzBuzz" - Otherwise → the number itself
- Node.js (latest LTS version)
git clone https://github.com/Erafle/fizz-buzz.git
cd fizz-buzz
npm installCreate a .env file at the root:
API_KEY=your-api-key# Development
npm run dev
# Production
npm run build
npm startReturns the FizzBuzz sequence for a given range.
| Header | Required | Description |
|---|---|---|
Authorization |
Yes | Must match API_KEY from .env |
| Parameter | Type | Default | Min | Max | Description |
|---|---|---|---|---|---|
from |
number | 1 |
1 | 100 | Start of the range |
to |
number | 100 |
1 | 100 | End of the range |
Note:
tomust be greater than or equal tofrom.
curl -H "Authorization: your-api-key" "http://localhost:3000/api/fizz-buzz?from=1&to=15"{
"data": [
1,
2,
"Fizz",
4,
"Buzz",
"Fizz",
7,
8,
"Fizz",
"Buzz",
11,
"Fizz",
13,
14,
"FizzBuzz"
]
}| Status | Name | When |
|---|---|---|
400 |
ValidationError |
Invalid or out-of-range query params |
401 |
UnauthorizedError |
Missing Authorization header or invalid API key |
500 |
InternalServerError |
Unexpected server error |