Draft
Conversation
HIPPIEKICK
requested changes
Dec 10, 2024
Contributor
HIPPIEKICK
left a comment
There was a problem hiding this comment.
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" | |||
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" }); | ||
| } | ||
|
|
||
| }); |
Contributor
There was a problem hiding this comment.
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 | ||
| } | ||
|
|
||
| }); |
Contributor
There was a problem hiding this comment.
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!"); | ||
| }); |
Contributor
There was a problem hiding this comment.
You forgot to list your endpoints 👀 Have a look at the instructions 😇
HIPPIEKICK
approved these changes
Jan 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Render link
https://project-17-express-api.onrender.com/
Collaborators