Skip to content

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.

server.js Outdated
@@ -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 😇

@erikamolsson erikamolsson marked this pull request as draft December 28, 2024 17:43
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