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

Climbing routes api - Zoe #535

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

Conversation

zoe-lindqvist
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.

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

Comment on lines +23 to +25
app.get("/climbingRoutes", (_, res) => {
res.json(climbingRoutes);
});
Copy link
Contributor

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.

Comment on lines +119 to +128
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");
}
});
Copy link
Contributor

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 👍

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