-
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
project-express-api - Elina Eriksson Hult #523
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 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) => { |
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 that you broke this out!
}; | ||
|
||
// Endpoint to fetch books filtered by language | ||
app.get("/books/language", filterBooksByLanguage); |
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.
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
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, | ||
}); | ||
}); |
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.
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" |
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.
Very helpful ⭐
https://project-express-api-elina.onrender.com