-
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 - deployed on Render - Emelie Nyberg #521
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.
Great job on creating your first RESTful API! You've done some nice filtering, just remember that sorting can be included as a query param as well (to keep it more RESTful).
Keep up the good work!
app.get("/videogames/sorted/ratings", (req, res) => { | ||
const sortedGames = videogames.sort((a, b) => b.rating - a.rating); | ||
res.json(sortedGames); | ||
}); |
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.
This could be another query param: ?sortOnRate=descending
or something
app.get("/videogames", (req, res) => { | ||
const category = req.query.category; | ||
const year = req.query.year; | ||
|
||
// Filter on category if category is sent | ||
// For example http://localhost:3000/videogames?category=racing | ||
if (category) { | ||
const filterCategory = videogames.filter(game => game.category.toLowerCase() === category); | ||
res.json(filterCategory); | ||
|
||
// Endpoint that returns a specific year | ||
// For example http://localhost:3000/videogames?year=2020 | ||
} if (year) { | ||
const videogameByYear = videogames.filter(game => game.release_year === +year); | ||
res.json(videogameByYear); | ||
|
||
// If no categori is sent, return all videogames | ||
// For example http://localhost:3000/videogames | ||
} else { | ||
res.json(videogames); | ||
}; | ||
}); |
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.
Excellent filtering!
Render link
https://project-express-api-ek.onrender.com