nextjs-course-code-08-prj-api-routes-starting-project

237. Adding a Newsletter Route
function registrationHandler(event) {
event.preventDefault();
const enteredEmail = emailInputRef.current.value;
**fetch("/api/newsletter", {
method: "POST",
body: JSON.stringify({
email: enteredEmail,
}),
headers: {
"Content-Type": "application/json",
},
})
.then((res) => res.json())
.then((data) => console.log(data));
}**
// pages/api/newsletter.js
function handler(req, res) {
if (req.method === "POST") {
const userEmail = req.body.email;
if (!userEmail || !userEmail.includes("@")) {
res.status(422).json({
message: "Invalid email address.",
});
return;
}
console.log(userEmail);
res.status(201).json({
message: "Signed up!",
});
}
}
export default handler;
238. Adding Comments API Routes
240. Setting Up A MongoDB Database
241. Running MongoDB Queries From Inside API Routes

application code
mongodb+srv://<username>:<password>@cluster0.tblijqc.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
how to set up