Skip to content

Conversation

@Fannyhenriques
Copy link

Comment on lines +102 to +115
app.get("/harryPotterCharacters/name/:name", async (req, res) => {
const name = req.params.name; // Extracting the name from the URL

try { // "new RegExp(`^${name}$`, "i")" ensures case-insensitive matching
const harryPotterCharacterName = await HarryPotterCharacter.findOne({ name: new RegExp(`^${name}$`, "i") });
if (harryPotterCharacterName) {
res.status(200).json(harryPotterCharacterName);
} else {
res.status(404).send("Sorry - no character found with that name");
}
} catch (error) {
res.status(400).json({ error: "Server error" });
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a query param under your main endpoint 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants