Closed glenncoppens closed 3 years ago
Nice idea! But it looks a little hard to implement 🤔
I didn't really check your current underlying approach to rename the keys.
But what if the object is flattened and thén the keys are being renamed (and then unflatten again)? Then you could include 'data.data'
or exclude 'data.meta'
..
But I'm afraid the problem here may be performance degradation 🤔
Not sure what performance impact of eg https://github.com/hughsk/flat is..
Yes, flattening all elements will have a large performance degradation. And we'll get into trouble on reshaping objects because this library accepts not only plain objects but also FormData
URLSearchParams
...
Extend CaseFunction
to accept 3rd argument like context
? But it may have a medium or large impact...
I'll close this since it looks quite hard to implement the feature without large breaking changes. But any PRs are still welcome, thanks.
Hi,
Nice work you did! So there's two options to preserve key names,
string[]
andFunction
. I'm currently using the string[] approach, but it might be useful to only apply the middleware only on a subset of the request/response data.Eg in a Json api there's (very often) extra metadata included in the response:
Can we use the Functions-approach here so that the casing middleware is only applied on the
data.data
attribute?Thanks!