Created
January 4, 2022 16:06
-
-
Save AkshayCHD/9a4d8f57645422854484dbc35ca9531d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
// Post API to add user to Database | |
app.post("/", async (req, res, next) => { | |
try { | |
const { profileId, name, dob, experience } = req.body; | |
const user = await saveUser({ profileId, name, dob, experience }); | |
res.json({ | |
message: "Inserted Successfully", | |
user: user, | |
}); | |
} catch (err) { | |
next(err); | |
} | |
}); | |
// Get API to get user by his profileId | |
app.get("/:profileId", async (req, res, next) => { | |
try { | |
const { profileId } = req.params; | |
const user = await getUser({ profileId }); | |
res.json({ | |
message: "Fetched Successfully", | |
user: user, | |
}); | |
} catch (err) { | |
next(err); | |
} | |
}); | |
app.listen(3030, () => { | |
console.log("Server started on port 3030"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment