-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Implement Model.withoutWrapping to return full response when set to false #55
Implement Model.withoutWrapping to return full response when set to false #55
Conversation
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 4 4
Lines 252 256 +4
Branches 45 47 +2
=====================================
+ Hits 252 256 +4
Continue to review full report at Codecov.
|
@peterquentin It is a good feature. But, once you do Maybe another strategy is just simply to do it like So, there is no need for |
@robsontenorio i see what you mean, basically you always want to alter the response in order to correctly consume it. In that case we would just need to remove 1 single check in resolveResponse. Please let me know if you agree so I can make the last changes. Edit: Also I would extract the response formatters to a helper class of some sorts instead of methods on the Model class. I got the polluting part. 👍 |
Basically, all the logic can be summarized in a simple check like this
For |
@robsontenorio how does that help exactly with the nested relation "data" problem? In this example post.comments.data |
I understand the reasoning not to pollute the Model object, but to preserve backwards compatibility I think something must be done, perhaps it's best just to extend Model into a new class with this unwrapping behaviour. |
@robsontenorio Any thoughts on the Model name that this functionality will have?
Not so sure about the name for this, please share your insights |
@peterquentin Please, give a try at this new branch and tell me if everything is working as expected https://github.com/robsontenorio/vue-api-query/tree/find-wrap |
@robsontenorio Nested "data" params are not removed. See my sample post.comments.data Ps: the find part was clear to me, but for the nested part you want a seperate model. Or did I not understand this correctly? |
Yes, i have focused only on About remove In another languages |
@robsontenorio, I think it could be if it's a seperate Model. Plus I check if the data type is an array. If its not possible, I think it would be usefull for newcomers to show them how they can best implement it on their own. Final check, curious on your viewpoint on this one. |
If you want to get ride off all nested “data” wrapper just implement a helper class on your frontend app, after getting a response from backend. Just like you did on PR. It is the same concept. The best scenario is to make the backend compliant, by removing that “data” wrapper. |
I am fine with implementing my own interface on top of this package to get rid of the data keys. But I must strongly disagree to the suggestion that we change our API to conform to your client software. As I mentioned originally, Laravel's JSON Resources actually default to using data keys in single resource responses. The JSON Api standard allows for nested data keys. So this is not an unusual requirement. Most importantly, we often are working with third-party API's that cannot be modified, or we are developing API's that are already being used by third parties. To change our API is not realistic. |
As I said it would be a “best scenario” for a new brand API. If not, you need to handle it by your own on frontend app. Edit: as mentioned on Readme, this package does not try to follow strictly JSon API specs. There are specifically packages for that. |
Fixes #54
You can disable response unwrapping by setting one simple var:
Tests included, please let me know if you can merge it 👍
Edit: Kind of a big change to support nested unwrapping of data.
Example API response, Model.
withoutWrapping
to false returns the same result:When Model.
withoutWrapping
is set to true (or not defined) we return it like this: