Should the first call be a GET or a POST?
It should be a GET
.
The key reason is that the client, if I'm following correctly, does not know it is creating a resource nor is setting out to create a resource.
The client wants the current state of the resource from the server. It is not aware this might mean creating a resource and it does not care one jolt that this is the first time anyone has attempted to get this resource before, nor that the server has to create the resource on its end (what ever that means in the context of the server).
The client just wants the current state of that resource.
REST has nothing to do with CRUD operations on the server side. In fact the point of REST is that those details should be hidden from the client. The client doesn't care at all what the server has to do to manage to give the client a representation of the resource. If the server has to run a big SQL query in a transaction to create this resource, client doesn't care.
The thing to remember here is the direction of control. The client is saying to the server give me your representation of resource foobar
. That is what GET is. how the server does that is up to the server.
If you used POST
or PUT
that is the client saying "Here is my representation of foobar
, update yourself"
But in your scenario the client isn't responsible for the initial creation of foobar
, the server is. The client just wants the server's representation and should be unaware of any side effects from that operation.
a
,b
, andc
? Without them, you wouldn't be able to use a GET as a creation mechanism. If you want to follow the "standard" precisely, GET can only get a resource that already exists.GET /bar/{bar_id}
when no resource exists still yields an error.