diff --git a/operations.js b/operations.js new file mode 100644 index 0000000..b406d03 --- /dev/null +++ b/operations.js @@ -0,0 +1,3 @@ +exports.powerFunction = function(x, y) { + return x ** y; +} diff --git a/server.js b/server.js index 31d08f3..73b1401 100755 --- a/server.js +++ b/server.js @@ -1,7 +1,34 @@ const express = require("express"); +const { powerFunction } = require("./operations"); +const { parseOperands } = require("./utils"); + const app = express(); +app.get("/add", (req, res) => { + const {x, y} = parseOperands(req); + const sum = add(x, y); + res.send(200, sum); +}); + +app.get("/subtract", (req, res) => { + const {x, y} = parseOperands(req); + const difference = subtract(x,y); + res.send(200, difference); +}); + +app.get("/multiply", (req, res) => { + const {x, y} = req.query; + const product = parseInt(x) * parseInt(y); + res.send(200, product); +}); + +app.get("/power", (req, res) => { + const {x, y} = parseOperands(req); + const power = powerFunction(x,y); + res.send(200, power); +}); + app.get("/", (req, res) => { res.send("Hello World"); }); diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..3a362bb --- /dev/null +++ b/utils.js @@ -0,0 +1,7 @@ +exports.parseOperands = function(req) { + const params = req.query; + return { + x: parseFloat(params.x), + y: parseFloat(params.y), + }; +} \ No newline at end of file