-
Notifications
You must be signed in to change notification settings - Fork 529
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon 👀
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" }); | ||
} | ||
|
||
}); |
There was a problem hiding this comment.
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
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 | ||
} | ||
|
||
}); |
There was a problem hiding this comment.
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 ⭐
app.get("/", (req, res) => { | ||
res.send("Hello Technigo!"); | ||
res.send("The animals of the world!"); | ||
}); |
There was a problem hiding this comment.
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 😇
Render link
https://project-17-express-api.onrender.com/
Collaborators