Skip to content

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