Skip to content

Instantly share code, notes, and snippets.

@AkshayCHD
Created January 4, 2022 16:06
Show Gist options
  • Save AkshayCHD/9a4d8f57645422854484dbc35ca9531d to your computer and use it in GitHub Desktop.
Save AkshayCHD/9a4d8f57645422854484dbc35ca9531d to your computer and use it in GitHub Desktop.
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