-
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
Climbing routes api - Zoe #535
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.
Good job with your first API Zoe! Just remember going forward that endpoints should be named after what they return so a RESTful approach is to include all filter options as query params in your main endpoint, e.g. /climbing-routes?type=sport&difficulty=low
app.get("/climbingRoutes", (_, res) => { | ||
res.json(climbingRoutes); | ||
}); |
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.
Instead of creating different endpoints for each filter/sorting option, you should just include all of the query params under this endpoint. This way you can also chain the filters, if anyone wants to filter on e.g. type and difficulty.
This is good practice to make your API RESTful.
app.get("/climbingRoutes/:id", (req, res) => { | ||
const id = req.params.id; | ||
|
||
const climbingRoute = climbingRoutes.find((route) => route.id === +id); | ||
if (climbingRoute) { | ||
res.json(climbingRoute); | ||
} else { | ||
res.status(404).send("No climbing route found with that ID"); | ||
} | ||
}); |
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 with some error handling as well 👍
Netlify link
https://project-express-api-mqhs.onrender.com/