Reputation: 97
I'm really new to mongodb and I want to build something to practice.
Imagine I have a collection that looks like this
{
"game": "stars",
"players": [
{
"name": "Jhon Smith",
"score": 10
}
]
}
Just a simply collection where I stored the name of a game and the players who are actually playing that game.
So, my routes will look like this
GET /games <- retrieves all the games
GET /games/:id <- find a game by id
GET /games/:id/players <- to get the players of a game
My questions are:
GET /games/:id/players
in order to get the games' players? I'm asking this and another question comes to my headUpvotes: 0
Views: 84
Reputation: 1289
Your routes are fine. There are probably many different opinions on the "best" way but I don't see any problem with the way you've done it.
Nope, the choice of database probably shouldn't affect the design of your API. In fact, this is one of the benefits of making an API...the consumers of the API don't need to know the database details behind it.
There are other options but I think the way you've done it is fine. Here's another option though if you'd like to see some other styles:
GET /players?gameId=123
Upvotes: 1