Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5be3d127bb | ||
|
|
aacb2f4287 | ||
|
|
d1edd55b36 |
14
src/routes/api/add.js
Normal file
14
src/routes/api/add.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const { input } = req.body;
|
||||
|
||||
res.json({ ret: input.a + input.b });
|
||||
});
|
||||
|
||||
router.get('/:a/:b', (req, res) => {
|
||||
res.json({ ret: Number(req.params.a) + Number(req.params.b) });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
14
src/routes/api/divide.js
Normal file
14
src/routes/api/divide.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const { input } = req.body;
|
||||
res.json({ ret: input.a / input.b });
|
||||
});
|
||||
|
||||
router.get('/:a/:b', (req, res) => {
|
||||
res.json({ ret: Number(req.params.a) / Number(req.params.b) });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
14
src/routes/api/multiply.js
Normal file
14
src/routes/api/multiply.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const { input } = req.body;
|
||||
res.json({ ret: input.a * input.b });
|
||||
});
|
||||
|
||||
router.get('/:a/:b', (req, res) => {
|
||||
res.json({ ret: Number(req.params.a) * Number(req.params.b) });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
14
src/routes/api/subtract.js
Normal file
14
src/routes/api/subtract.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const { input } = req.body;
|
||||
res.json({ ret: input.a - input.b });
|
||||
});
|
||||
|
||||
router.get('/:a/:b', (req, res) => {
|
||||
res.json({ ret: Number(req.params.a) - Number(req.params.b) });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -287,6 +287,266 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/add": {
|
||||
"post": {
|
||||
"summary": "Adds two numbers",
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "number",
|
||||
"example": 5
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"example": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/add/{a}/{b}": {
|
||||
"get": {
|
||||
"summary": "Adds two numbers from path parameters",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "5"
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "10"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/subtract": {
|
||||
"post": {
|
||||
"summary": "Subtracts second number from first",
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "number",
|
||||
"example": 10
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"example": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/subtract/{a}/{b}": {
|
||||
"get": {
|
||||
"summary": "Subtracts second number from first from path parameters",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "10"
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "5"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/multiply": {
|
||||
"post": {
|
||||
"summary": "Multiplies two numbers",
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "number",
|
||||
"example": 5
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"example": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/multiply/{a}/{b}": {
|
||||
"get": {
|
||||
"summary": "Multiplies two numbers from path parameters",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "5"
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "10"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/divide": {
|
||||
"post": {
|
||||
"summary": "Divides first number by second",
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "number",
|
||||
"example": 10
|
||||
},
|
||||
"b": {
|
||||
"type": "number",
|
||||
"example": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/divide/{a}/{b}": {
|
||||
"get": {
|
||||
"summary": "Divides first number by second from path parameters",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "a",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "10"
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "2"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ const isOddRoute = require('./routes/api/isOdd');
|
||||
const toStringRoute = require('./routes/api/toString');
|
||||
const isNumberRoute = require('./routes/api/isNumber');
|
||||
const stringSplitRoute = require('./routes/api/stringSplit');
|
||||
const addRoute = require('./routes/api/add');
|
||||
const subtractRoute = require('./routes/api/subtract');
|
||||
const multiplyRoute = require('./routes/api/multiply');
|
||||
const divideRoute = require('./routes/api/divide');
|
||||
|
||||
|
||||
const docsRoute = require('./routes/docs/main');
|
||||
|
||||
const app = express();
|
||||
@@ -24,6 +30,12 @@ app.use('/api/isOdd', isOddRoute);
|
||||
app.use('/api/toString', toStringRoute);
|
||||
app.use('/api/isNumber', isNumberRoute);
|
||||
app.use('/api/stringSplit', stringSplitRoute);
|
||||
app.use('/api/add', addRoute);
|
||||
app.use('/api/subtract', subtractRoute);
|
||||
app.use('/api/multiply', multiplyRoute);
|
||||
app.use('/api/divide', divideRoute);
|
||||
|
||||
|
||||
app.use('/docs', docsRoute);
|
||||
|
||||
app.listen(PORT, () => {
|
||||
|
||||
Reference in New Issue
Block a user