var express = require("express");
var router = express();
var cors = require("cors");
// Allow CORS
router.use(cors());
router.use(express.json());
router.post('/numbertostring', (req, res) => {
console.log("numbertostring in");
console.log("Value="+ req.body.input);
var returnvalue={};
returnvalue.returnvalue = String(req.body.input);
res.json(returnvalue);
})
router.post('/stringtonumber', (req, res) => {
console.log("stringtonumber in");
console.log("Value="+ req.body.input);
var returnvalue={};
//NOTE : This part should originally describe the logic for the case where conversion to a numeric type is not possible.
returnvalue.returnvalue = Number(req.body.input);
res.json(returnvalue);
})
router.listen(process.env.PORT || 4000);
{
"openapi": "3.0.0",
"info": {
"title": "String to Number and Number to String Converter",
"version": "1.0.0",
"description": "A sample API to convert string to number and number to string."
},
"paths": {
"/stringtonumber": {
"post": {
"summary": "Converts a string to a number",
"requestBody": {
"description": "Input JSON object containing the string to be converted to a number",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "string",
"example": "123"
}
},
"required": ["input"]
}
}
}
},
"responses": {
"200": {
"description": "Successful response with the converted number",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"returnvalue": {
"type": "number",
"example": 123
}
}
}
}
}
}
}
}
},
"/numbertostring": {
"post": {
"summary": "Converts a number to a string",
"requestBody": {
"description": "Input JSON object containing the number to be converted to a string",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "number",
"example": 123
}
},
"required": ["input"]
}
}
}
},
"responses": {
"200": {
"description": "Successful response with the converted string",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"returnvalue": {
"type": "string",
"example": "123"
}
}
}
}
}
}
}
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
22 | |
19 | |
13 | |
10 | |
9 | |
9 | |
8 | |
7 | |
7 |