3

Here is a small description about what I am trying to do

  1. Build a set of APIs for online game play
  2. my GET API i want to return all open games (list of gameIds) GET /api/games/
  3. my POST API i want to create a new game POST /api/games/

My question is what should my POST API return. Ideally I would want client to know the gameId of the newly created game, so that all operations specific to the game can then use following syntax /api/games/gameId

Any suggestions, on how I communicate this gameId back to client?

Sandy
  • 2,253
  • 6
  • 24
  • 33
  • You could just return the uri for the newly created resource, in the location header, with 201 created – Paul Samsotha Oct 12 '14 at 10:30
  • One option is to include not only the ID, but the full URL for subsequent access, an idea which goes by the rather lengthy name of HATEOAS. – IMSoP Oct 12 '14 at 10:31

1 Answers1

4

You should return 201, Created as the response code. The location header should contain the URL of the newly created resource (ie. /api/games/new_game_id).

Full details can be found in the answers to this question, in particular the reference to the RFC.

Community
  • 1
  • 1
rmcsharry
  • 5,363
  • 6
  • 65
  • 108