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

project-express-api - Elina Eriksson Hult #523

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

Conversation

ElinaEH
Copy link

@ElinaEH ElinaEH commented Dec 6, 2024

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 Elina with your first API! Just remember going forward that all endpoints should be named after what they return and that you can make use of query params

});

// Function to filter books by their language
const filterBooksByLanguage = (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that you broke this out!

};

// Endpoint to fetch books filtered by language
app.get("/books/language", filterBooksByLanguage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more RESTful if this was a query param in the /books endpoint instead of its own endpoint, e.g. /books?language=english

Comment on lines 69 to 75
app.get("/", (req, res) => {
res.send("Hello Technigo!");
const endpoints = listEndpoints(app); // Fetch all endpoints
res.json({
message: "Welcome to the Book API 📚 Here are the available endpoints:",
endpoints: endpoints,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually order my endpoints from the most general to the most specific. Is there a reason why you put this last? 👀

} else {
res.status(404).json({
error: `No books found for this language: ${language}`,
example_usage: "Try this: /books/language?language=spa"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful ⭐

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