diff --git a/server.js b/server.js new file mode 100644 index 0000000000000000000000000000000000000000..6c8338ec57709ce59ee326418163f8ab492232f4 --- /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}`); +});