Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

harrypotter-mongo-api #518

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

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