You have to add your specific mapping on the method, not class.
For consistency you should either stick to singular or plural noun in your path. E.g. Player vs Players or Game vs Games. I prefer singular noun for my rest services - but this is mostly a subjective opinion. Just remember your path should only contain nouns and never verbs(Actions such as create, retrieve, update...). HTTP Methods such as GET, POST, PUT, DETELE are your actions, there is therefore no need for verbs in your path..
You can return the resource by different approaches. I recommend you reading this question
@RestController
@RequestMapping("${spring.data.rest.base-path}" + "/player")
public class PlayerRestResource {
//This method can be accessed from /player/3
//Id need to be placed in curly. 3 from url will be passed to the method
@RequestMapping(path = "/{playerId}", method = RequestMethod.POST)
//Use @PathVariable to bind the value from to url to the method parameter.
public ResponseEntity<Player> getPlayer(@PathVariable("playerId") int playerId) {
}
//This is just like the above method.
//This method can be accessed from /player/3/game/5
@RequestMapping(path = "/{playerId}/game/{gameId}" method = RequestMethod.POST)
public ResponseEntity<List<Game>> getGame(@PathVariable("playerId) int playerId, @PathVariable("gameId) int gameId) {
}
}
A quick crash-course in formatting rest services.
You always want to build on top of your path. The base variable should be your base entity.
Create new player - Payload could be formatted as JSON in body
POST: example.com/player
Retrieve information about player with ID 3.
GET: example.com/player/3
Update information about player with ID 3 - Payload could be formatted as JSON in body
PUT: example.com/player/3
Delete player with ID 3
DELETE: example.com/player/3
Retrieve information about game with ID 5 that is associated with player with ID 3. Please note, that this is path should be used to update data on a specific player for a specific user
GET: example.com/player/3/game/5
Create new game - Payload could be formatted as JSON in body
POST: example.com/game
Retrieve information about game with ID 5 - This data is not associated with any players. This is only data about the specific game with ID 5
GET: example.com/player/5
All your paths starting with /player should go into a PlayerController class, and all the paths starting with /game should be in GameController class.
I would suggest you to read the following resources:
https://martinfowler.com/articles/richardsonMaturityModel.html
https://www.restapitutorial.com/
https://spring.io/guides/tutorials/bookmarks/