Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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;
|
||||||
@@ -287,6 +287,71 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ const isOddRoute = require('./routes/api/isOdd');
|
|||||||
const toStringRoute = require('./routes/api/toString');
|
const toStringRoute = require('./routes/api/toString');
|
||||||
const isNumberRoute = require('./routes/api/isNumber');
|
const isNumberRoute = require('./routes/api/isNumber');
|
||||||
const stringSplitRoute = require('./routes/api/stringSplit');
|
const stringSplitRoute = require('./routes/api/stringSplit');
|
||||||
|
const addRoute = require('./routes/api/add');
|
||||||
|
|
||||||
|
|
||||||
const docsRoute = require('./routes/docs/main');
|
const docsRoute = require('./routes/docs/main');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -24,6 +27,9 @@ app.use('/api/isOdd', isOddRoute);
|
|||||||
app.use('/api/toString', toStringRoute);
|
app.use('/api/toString', toStringRoute);
|
||||||
app.use('/api/isNumber', isNumberRoute);
|
app.use('/api/isNumber', isNumberRoute);
|
||||||
app.use('/api/stringSplit', stringSplitRoute);
|
app.use('/api/stringSplit', stringSplitRoute);
|
||||||
|
app.use('/api/add', addRoute);
|
||||||
|
|
||||||
|
|
||||||
app.use('/docs', docsRoute);
|
app.use('/docs', docsRoute);
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user