Vuejs: Separate requests to separate routes vs. post to an update route - What is better design in your perspective?

Posted 2 years ago by EventFellows

Let's say the following is the case:

  • a blog where users can make posts
  • user has a list of his own posts in his account
  • user should have option to perform different simple actions on an existing post (publish, unpublish, highlight, push to front page)
  • using vuejs

What is the better conecpt to approach that - submit a form vs. send requests to specific routes

Scenario 1

I could imagine is: send a request to a restful route (in a .js file):

        publishPost() {
            this.$http.patch('/api/posts/' + this.post.id + '/publish')
                .then(() => {
                    // handle success
                })
                .catch(response => {
                    // handle failure
                });
        },

and in a similar way for other actions.

Scenario 2

would be to use a single form with several named submit buttons and catch the action in the backend with just a sinlge route.

        updatePost() {
            this.$http.post('/api/posts/' + this.post.id, updatePostForm)
                .then(() => {
                    // handle success
                })
                .catch(response => {
                    // handle failure
                });
        },

Without having completed it I would expect both approaches to work but I am unsure on what the better approach would be.

Thoughts?

Please sign in or create an account to participate in this conversation.