Skip to content
Snippets Groups Projects
Commit e4ff624c authored by Bhavyarani Suvarna's avatar Bhavyarani Suvarna
Browse files

adding server file for getapi and post api

parent a78630ad
No related branches found
No related tags found
No related merge requests found
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}`);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment