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

project-17-express-api #522

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

Conversation

erikamolsson
Copy link

Copy link
Contributor

@HIPPIEKICK HIPPIEKICK left a comment

Choose a reason for hiding this comment

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

Amazing job Erika! Just include the docs and you're good to go.

@@ -1,30 +1,74 @@
import express from "express";
import cors from "cors";
import animals from "./data/animals.json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing semicolon 👀

Comment on lines +41 to +54
app.get("/regions/:region", (req, res) => {
const region = req.params.region;

const specificRegion = animals.filter((animal) =>
animal.region.toLowerCase().includes(region)
);

if (specificRegion) {
res.json(specificRegion);
} else {
res.status(404).json({ error: "Animal not found" });
}

});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to see some additional filtering! Just remember that a RESTful API names its routes after what they return (and you return animals here). Therefor, a more RESTful approach would be to include it as query params in your /animals route:
/animals?region=worldwide

Comment on lines +58 to 68
app.get("/traits/:name", (req, res) => {
const name = req.params.name; // Get the name from the route
const animal = animals.find((a) => a.name.toLowerCase() === name); // Find the animal by name

if (animal) {
res.json({ name: animal.name, trait: animal.trait }); // Respond with the name and trait
} else {
res.status(404).json({ error: "Animal not found" }); // Animal not found
}

});
Copy link
Contributor

Choose a reason for hiding this comment

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

I was close to saying the same thing about this endpoint, but here you are actually returning the trait, so it's all good ⭐

Comment on lines 18 to +20
app.get("/", (req, res) => {
res.send("Hello Technigo!");
res.send("The animals of the world!");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to list your endpoints 👀 Have a look at the instructions 😇

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