Description
With POST requests, the semantic implication is often that we POST to a collection, and the response contains a newly created entity that has a new self URI. In this case, the collection in the store will not contain the new entity after the response has arrived.
We could consider adding a configurable option or flag to the post
/ $post
functions that allows to automatically reload the collection after the POST request has completed. This seems like a usual pattern that hal-json-vuex users would have to do manually otherwise, and it would be similar to the behaviour of delete
, where we reload any collection and entity that "know" the deleted entity.
We should probably only reload the collection if it was loaded in the store already.
Thoughts on this? I'd imagine to use it like this:
// will automatically reload /books after the POST was successful
this.api.get().books().$post({ name: 'Moby Dick' })
// disable auto-reloading the collection
this.api.get().books().$post({ name: 'Winnetou' }, { reload: false })
this.api.purgeAll()
// will not reload the whole /books collection when we don't already know it
// (at the point in time after the POST request has finished)
this.api.post(await this.api.get().$href('books'), { name: 'Harry Potter' })