From e4ff624cc146b413fe779b13d678c4df46c96c50 Mon Sep 17 00:00:00 2001 From: "bhavyarani.suvarna" <bhavyarani.suvarna@niveussolutions.com> Date: Fri, 21 Feb 2025 12:46:55 +0530 Subject: [PATCH] adding server file for getapi and post api --- server.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 server.js diff --git a/server.js b/server.js new file mode 100644 index 0000000..6c8338e --- /dev/null +++ b/server.js @@ -0,0 +1,35 @@ +const express = require("express"); +const app = express(); + +// Middleware to parse JSON data +app.use(express.json()); + +const PORT = 3000; + +// GET API - Returns path param & query param +app.get("/user/:id", (req, res) => { + const pathParam = req.params.id; + const queryParam = req.query.name; + + res.json({ + message: "GET API Response", + pathParam: pathParam, + queryParam: queryParam, + }); +}); + +// Array to store POST data +const dataStore = []; + +app.post("/data", (req, res) => { + const receivedData = req.body; + + dataStore.push(receivedData); + + res.json(dataStore); +}); + +// Start the server +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +}); -- GitLab