I’ve got a situation where a client app can ask for a resource matching certain criteria, and if a matching resource does not exist it is created and cached. Subsequent requests for the same criteria will return the cached resource.
I could implement this via a PUT request to create the resource and subsequent GETs. However, in my particular scenario that requires the client to know too much about the internal workings of my system i.e. the client shouldn’t care whether the resource already exists or not.
So is it ReSTful to allow the client to make a single GET request that happens to create the resource if it doesn’t already exist?
Theoretically GET should just GET, and not change the state of your system. See idempotency.
Paragraph from Wikipedia:
However, in your scenario an initial GET is setting up a resource purely for caching. Subsequent calls won’t change the state of the system, so I’d suggest that GET is fine in this scenario.