christianmalek / vuex-rest-api

A utility to simplify the use of REST APIs with Vuex
http://vuex-rest-api.org
MIT License
382 stars 48 forks source link

[QUESTION] - Pre API Call Transformation #77

Closed go4cas closed 6 years ago

go4cas commented 6 years ago

First off ... awesome library!

I want to know if there is a way of transforming the request payload before calling the API? At present I can use OnSuccess to transform the response payload I get back from my back-end API, but for my use case I need to transform the payload, before POST and PUT requests.

go4cas commented 6 years ago

Okay, I see that in 2.9.0 a new beforeRequest was introduced. I'm just not sure how to change the data object using this. Or, should I rather do the transformation in requestConfig -> transformRequest?

christianmalek commented 6 years ago

Hey @go4cas ! The beforeRequest method was added to update your store optimistically (before you got the response from the server with the actual data).

If you need to transform your data doing it via requestConfig.transformRequest is at the moment the proper way to go. Mhm. Maybe I should add another method to do this without fiddling in the requestConfig. 🤔

christianmalek commented 6 years ago

I'll close this. Feel free to open a new issue.