1 Commits

Author SHA1 Message Date
johannesbot 56bd3ea604 20 new API endpoints
Build and Deploy / build (push) Successful in 30s
Build Release / build (push) Successful in 22s
Build and Deploy / deploy (push) Successful in 26s
2026-06-17 06:24:22 +02:00
22 changed files with 856 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input) || input.length === 0)
return res.status(400).json({ error: 'input must be a non-empty array' });
res.json({ ret: Math.max(...input.map(Number)) });
});
module.exports = router;
+11
View File
@@ -0,0 +1,11 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input) || input.length === 0)
return res.status(400).json({ error: 'input must be a non-empty array' });
res.json({ ret: Math.min(...input.map(Number)) });
});
module.exports = router;
+10
View File
@@ -0,0 +1,10 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) return res.status(400).json({ error: 'input must be an array' });
res.json({ ret: [...new Set(input)] });
});
module.exports = router;
+11
View File
@@ -0,0 +1,11 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input) || input.length === 0)
return res.status(400).json({ error: 'input must be a non-empty array' });
res.json({ ret: input.reduce((acc, n) => acc + Number(n), 0) / input.length });
});
module.exports = router;
+10
View File
@@ -0,0 +1,10 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) return res.status(400).json({ error: 'input must be an array' });
res.json({ ret: input.reduce((acc, n) => acc + Number(n), 0) });
});
module.exports = router;
+22
View File
@@ -7,6 +7,10 @@ router.use('/subtract', require('./math/subtract'));
router.use('/multiply', require('./math/multiply'));
router.use('/divide', require('./math/divide'));
router.use('/modulo', require('./math/modulo'));
router.use('/power', require('./math/power'));
router.use('/abs', require('./math/abs'));
router.use('/factorial', require('./math/factorial'));
router.use('/isPrime', require('./math/isPrime'));
// String
router.use('/toString', require('./string/toString'));
@@ -17,21 +21,39 @@ router.use('/stringLength', require('./string/stringLength'));
router.use('/countWords', require('./string/countWords'));
router.use('/toUpperCase', require('./string/toUpperCase'));
router.use('/toLowerCase', require('./string/toLowerCase'));
router.use('/repeat', require('./string/repeat'));
router.use('/trimString', require('./string/trimString'));
router.use('/stringContains', require('./string/stringContains'));
router.use('/randomCase', require('./string/randomCase'));
// Array
router.use('/sort', require('./array/sort'));
router.use('/reverseArray', require('./array/reverseArray'));
router.use('/sum', require('./array/sum'));
router.use('/average', require('./array/average'));
router.use('/arrayMax', require('./array/arrayMax'));
router.use('/arrayMin', require('./array/arrayMin'));
router.use('/arrayUnique', require('./array/arrayUnique'));
// Checks
router.use('/isEven', require('./checks/isEven'));
router.use('/isOdd', require('./checks/isOdd'));
router.use('/isNumber', require('./checks/isNumber'));
// Misc
router.use('/coinFlip', require('./misc/coinFlip'));
router.use('/diceRoll', require('./misc/diceRoll'));
router.use('/fizzBuzz', require('./misc/fizzBuzz'));
// Meme sorts
router.use('/stalinSort', require('./sorts/stalinSort'));
router.use('/bogoSort', require('./sorts/bogoSort'));
router.use('/thanoSort', require('./sorts/thanoSort'));
router.use('/sleepSort', require('./sorts/sleepSort'));
router.use('/miracleSort', require('./sorts/miracleSort'));
router.use('/intelligentDesignSort', require('./sorts/intelligentDesignSort'));
router.use('/quantumSort', require('./sorts/quantumSort'));
router.use('/pancakeSort', require('./sorts/pancakeSort'));
router.use('/gnomeSort', require('./sorts/gnomeSort'));
module.exports = router;
+13
View File
@@ -0,0 +1,13 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: Math.abs(Number(input)) });
});
router.get('/:n', (req, res) => {
res.json({ ret: Math.abs(Number(req.params.n)) });
});
module.exports = router;
+23
View File
@@ -0,0 +1,23 @@
const express = require('express');
const router = express.Router();
function factorial(n) {
if (n === 0 || n === 1) return 1;
let result = 1;
for (let i = 2; i <= n; i++) result *= i;
return result;
}
router.post('/', (req, res) => {
const n = Math.floor(Number(req.body.input));
if (n < 0 || n > 170) return res.status(400).json({ error: 'n must be between 0 and 170' });
res.json({ ret: factorial(n) });
});
router.get('/:n', (req, res) => {
const n = Math.floor(Number(req.params.n));
if (n < 0 || n > 170) return res.status(400).json({ error: 'n must be between 0 and 170' });
res.json({ ret: factorial(n) });
});
module.exports = router;
+23
View File
@@ -0,0 +1,23 @@
const express = require('express');
const router = express.Router();
function isPrime(n) {
if (n < 2) return false;
if (n === 2) return true;
if (n % 2 === 0) return false;
for (let i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i === 0) return false;
}
return true;
}
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: isPrime(Math.floor(Number(input))) });
});
router.get('/:n', (req, res) => {
res.json({ ret: isPrime(Math.floor(Number(req.params.n))) });
});
module.exports = router;
+13
View File
@@ -0,0 +1,13 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: Math.pow(input.a, input.b) });
});
router.get('/:a/:b', (req, res) => {
res.json({ ret: Math.pow(Number(req.params.a), Number(req.params.b)) });
});
module.exports = router;
+8
View File
@@ -0,0 +1,8 @@
const express = require('express');
const router = express.Router();
router.get('/', (req, res) => {
res.json({ ret: Math.random() < 0.5 ? 'heads' : 'tails' });
});
module.exports = router;
+13
View File
@@ -0,0 +1,13 @@
const express = require('express');
const router = express.Router();
router.get('/', (req, res) => {
res.json({ ret: Math.floor(Math.random() * 6) + 1 });
});
router.get('/:sides', (req, res) => {
const sides = Math.max(2, Math.floor(Number(req.params.sides)));
res.json({ ret: Math.floor(Math.random() * sides) + 1, sides });
});
module.exports = router;
+20
View File
@@ -0,0 +1,20 @@
const express = require('express');
const router = express.Router();
function fizzBuzz(n) {
if (n % 15 === 0) return 'FizzBuzz';
if (n % 3 === 0) return 'Fizz';
if (n % 5 === 0) return 'Buzz';
return n;
}
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: fizzBuzz(Number(input)) });
});
router.get('/:n', (req, res) => {
res.json({ ret: fizzBuzz(Number(req.params.n)) });
});
module.exports = router;
+25
View File
@@ -0,0 +1,25 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) return res.status(400).json({ error: 'input must be an array' });
const arr = [...input];
let pos = 0;
let moves = 0;
while (pos < arr.length) {
if (pos === 0 || arr[pos] >= arr[pos - 1]) {
pos++;
} else {
[arr[pos], arr[pos - 1]] = [arr[pos - 1], arr[pos]];
pos--;
moves++;
}
}
res.json({ ret: arr, moves });
});
module.exports = router;
@@ -0,0 +1,13 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) return res.status(400).json({ error: 'input must be an array' });
res.json({
ret: input,
message: 'The array has been sorted by a higher power. Who are we to question it?'
});
});
module.exports = router;
+35
View File
@@ -0,0 +1,35 @@
const express = require('express');
const router = express.Router();
function flip(arr, k) {
let left = 0;
while (left < k) {
[arr[left], arr[k]] = [arr[k], arr[left]];
left++;
k--;
}
}
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) return res.status(400).json({ error: 'input must be an array' });
const arr = [...input];
const flips = [];
for (let size = arr.length; size > 1; size--) {
const maxIdx = arr.slice(0, size).indexOf(Math.max(...arr.slice(0, size)));
if (maxIdx !== size - 1) {
if (maxIdx !== 0) {
flip(arr, maxIdx);
flips.push(maxIdx + 1);
}
flip(arr, size - 1);
flips.push(size);
}
}
res.json({ ret: arr, flips, totalFlips: flips.length });
});
module.exports = router;
+15
View File
@@ -0,0 +1,15 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) return res.status(400).json({ error: 'input must be an array' });
res.json({
ret: [...input].sort((a, b) => a - b),
universeCollapsed: true,
parallelUniversesDestroyed: Math.pow(2, input.length),
message: 'Wave function collapsed successfully. All other quantum states have been discarded.'
});
});
module.exports = router;
+19
View File
@@ -0,0 +1,19 @@
const express = require('express');
const router = express.Router();
function randomCase(str) {
return String(str).split('').map(c =>
Math.random() > 0.5 ? c.toUpperCase() : c.toLowerCase()
).join('');
}
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: randomCase(input) });
});
router.get('/:string', (req, res) => {
res.json({ ret: randomCase(req.params.string) });
});
module.exports = router;
+10
View File
@@ -0,0 +1,10 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
const times = Math.min(Math.max(0, Math.floor(Number(input.times))), 1000);
res.json({ ret: String(input.string).repeat(times) });
});
module.exports = router;
+9
View File
@@ -0,0 +1,9 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: String(input.string).includes(String(input.search)) });
});
module.exports = router;
+13
View File
@@ -0,0 +1,13 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: String(input).trim() });
});
router.get('/:string', (req, res) => {
res.json({ ret: req.params.string.trim() });
});
module.exports = router;
+529
View File
@@ -20,6 +20,7 @@
{ "name": "String", "description": "String manipulation" },
{ "name": "Array", "description": "Array operations" },
{ "name": "Checks", "description": "Value checking" },
{ "name": "Misc", "description": "Miscellaneous fun endpoints" },
{ "name": "Sorts", "description": "Sorting algorithms (serious and meme)" }
],
"paths": {
@@ -718,6 +719,534 @@
}
}
}
},
"/power": {
"post": {
"tags": ["Math"],
"summary": "Raises a to the power of b (a^b)",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"a": { "type": "number", "example": 2 },
"b": { "type": "number", "example": 8 }
}
}
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/power/{a}/{b}": {
"get": {
"tags": ["Math"],
"summary": "Raises a to the power of b from path parameters",
"parameters": [
{ "name": "a", "in": "path", "required": true, "schema": { "type": "string" }, "example": "2" },
{ "name": "b", "in": "path", "required": true, "schema": { "type": "string" }, "example": "8" }
],
"responses": { "200": { "description": "Success" } }
}
},
"/abs": {
"post": {
"tags": ["Math"],
"summary": "Returns the absolute value of a number",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": { "input": { "type": "number", "example": -42 } }
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/abs/{n}": {
"get": {
"tags": ["Math"],
"summary": "Returns the absolute value from path parameter",
"parameters": [
{ "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "-42" }
],
"responses": { "200": { "description": "Success" } }
}
},
"/factorial": {
"post": {
"tags": ["Math"],
"summary": "Calculates n! (0170)",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": { "input": { "type": "number", "example": 5 } }
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/factorial/{n}": {
"get": {
"tags": ["Math"],
"summary": "Calculates n! from path parameter",
"parameters": [
{ "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "5" }
],
"responses": { "200": { "description": "Success" } }
}
},
"/isPrime": {
"post": {
"tags": ["Math"],
"summary": "Checks if a number is prime",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": { "input": { "type": "number", "example": 17 } }
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/isPrime/{n}": {
"get": {
"tags": ["Math"],
"summary": "Checks if a number is prime from path parameter",
"parameters": [
{ "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "17" }
],
"responses": { "200": { "description": "Success" } }
}
},
"/repeat": {
"post": {
"tags": ["String"],
"summary": "Repeats a string n times (max 1000)",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"string": { "type": "string", "example": "ha" },
"times": { "type": "number", "example": 3 }
}
}
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/trimString": {
"post": {
"tags": ["String"],
"summary": "Trims leading and trailing whitespace from a string",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": { "input": { "type": "string", "example": " hello " } }
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/trimString/{string}": {
"get": {
"tags": ["String"],
"summary": "Trims whitespace from path parameter",
"parameters": [
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" } }
],
"responses": { "200": { "description": "Success" } }
}
},
"/stringContains": {
"post": {
"tags": ["String"],
"summary": "Checks if a string contains a substring",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"string": { "type": "string", "example": "hello world" },
"search": { "type": "string", "example": "world" }
}
}
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/randomCase": {
"post": {
"tags": ["String"],
"summary": "Randomly capitalizes letters (sPoNgEbOb CaSe)",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": { "input": { "type": "string", "example": "mocking spongebob" } }
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/randomCase/{string}": {
"get": {
"tags": ["String"],
"summary": "Randomly capitalizes letters from path parameter",
"parameters": [
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "hello" }
],
"responses": { "200": { "description": "Success" } }
}
},
"/sum": {
"post": {
"tags": ["Array"],
"summary": "Sums all elements of an array",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": { "type": "number" }, "example": [1, 2, 3, 4, 5] }
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/average": {
"post": {
"tags": ["Array"],
"summary": "Calculates the average of all elements in an array",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": { "type": "number" }, "example": [1, 2, 3, 4, 5] }
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/arrayMax": {
"post": {
"tags": ["Array"],
"summary": "Returns the largest element in an array",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": { "type": "number" }, "example": [3, 1, 4, 1, 5, 9] }
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/arrayMin": {
"post": {
"tags": ["Array"],
"summary": "Returns the smallest element in an array",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": { "type": "number" }, "example": [3, 1, 4, 1, 5, 9] }
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/arrayUnique": {
"post": {
"tags": ["Array"],
"summary": "Removes duplicate elements from an array",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": {}, "example": [1, 2, 2, 3, 3, 3] }
}
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/coinFlip": {
"get": {
"tags": ["Misc"],
"summary": "Flips a coin — returns heads or tails",
"responses": { "200": { "description": "heads or tails" } }
}
},
"/diceRoll": {
"get": {
"tags": ["Misc"],
"summary": "Rolls a standard 6-sided dice",
"responses": { "200": { "description": "Number between 1 and 6" } }
}
},
"/diceRoll/{sides}": {
"get": {
"tags": ["Misc"],
"summary": "Rolls a dice with a custom number of sides",
"parameters": [
{ "name": "sides", "in": "path", "required": true, "schema": { "type": "string" }, "example": "20" }
],
"responses": { "200": { "description": "Number between 1 and sides" } }
}
},
"/fizzBuzz": {
"post": {
"tags": ["Misc"],
"summary": "Returns Fizz, Buzz, FizzBuzz or the number itself",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": { "input": { "type": "number", "example": 15 } }
}
}
}
},
"responses": { "200": { "description": "Success" } }
}
},
"/fizzBuzz/{n}": {
"get": {
"tags": ["Misc"],
"summary": "FizzBuzz from path parameter",
"parameters": [
{ "name": "n", "in": "path", "required": true, "schema": { "type": "string" }, "example": "15" }
],
"responses": { "200": { "description": "Success" } }
}
},
"/intelligentDesignSort": {
"post": {
"tags": ["Sorts"],
"summary": "Sorts an array using Intelligent Design Sort",
"description": "The array is already perfectly sorted by a higher power. Who are we to question it?",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": {}, "example": [3, 1, 4, 1, 5] }
}
}
}
}
},
"responses": {
"200": {
"description": "The untouched array with a divine message",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"ret": { "type": "array", "items": {} },
"message": { "type": "string" }
}
}
}
}
}
}
}
},
"/quantumSort": {
"post": {
"tags": ["Sorts"],
"summary": "Sorts an array using Quantum Sort",
"description": "Collapses the quantum superposition into the only sorted universe. All parallel universes with unsorted arrays are destroyed.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": { "type": "number" }, "example": [3, 1, 4, 1, 5] }
}
}
}
}
},
"responses": {
"200": {
"description": "Sorted array with quantum collapse metadata",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"ret": { "type": "array", "items": {} },
"universeCollapsed": { "type": "boolean" },
"parallelUniversesDestroyed": { "type": "number" },
"message": { "type": "string" }
}
}
}
}
}
}
}
},
"/pancakeSort": {
"post": {
"tags": ["Sorts"],
"summary": "Sorts an array using Pancake Sort",
"description": "Sorts by repeatedly flipping prefixes of the array, like flipping a stack of pancakes.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": {}, "example": [3, 1, 4, 1, 5] }
}
}
}
}
},
"responses": {
"200": {
"description": "Sorted array with flip history",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"ret": { "type": "array", "items": {} },
"flips": { "type": "array", "items": { "type": "number" } },
"totalFlips": { "type": "number" }
}
}
}
}
}
}
}
},
"/gnomeSort": {
"post": {
"tags": ["Sorts"],
"summary": "Sorts an array using Gnome Sort",
"description": "A gnome sorts by looking at the current and previous flower pot. If they are in the wrong order, it swaps them and steps back.",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": { "type": "array", "items": {}, "example": [3, 1, 4, 1, 5] }
}
}
}
}
},
"responses": {
"200": {
"description": "Sorted array with move count",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"ret": { "type": "array", "items": {} },
"moves": { "type": "number" }
}
}
}
}
}
}
}
}
}
}