Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-reload collection after POSTing #93

Open
carlobeltrame opened this issue Apr 23, 2021 · 0 comments
Open

Auto-reload collection after POSTing #93

carlobeltrame opened this issue Apr 23, 2021 · 0 comments

Comments

@carlobeltrame
Copy link
Member

carlobeltrame commented Apr 23, 2021

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' }) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant