-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: wrap request body with data
key
#55
Conversation
I just added a draft PR, remaining two problems to resolve/discuss: Avoiding polluting non-Content API requestsIn a middleware, I don't have a perfect solution for this. But two ugly workarounds: 😔
Possibility of "Smart" modeIn the beginning, I believed we could wrap with // in middleware
let reqBody = ctx.request.body;
if (!('data' in reqBody)) { // 👈 "smart" detection
reqBody = { data: reqBody };
ctx.request.body = reqBody;
} Unfortunately, this "smart" detection could be wrong, if an entry object has its own // body of a POST or PUT request
-{
"foo": "...",
"bar": "...",
"data": { /* ... */ },
} The above needs to be wrapped, but the "smart" detection failed to figure out. Then I realized there's no way "smart" enough. Might as well set this feature as "Force" mode -- if the config is on, we wrap; if not, we do nothing. |
Great start! I have refactored some of the code (using your work as a base) to be more inline with the rest of the codebase. Avoiding polluting non-Content API requestsI am not a fan of either of those options, I will need to think more on this. I was originally thinking we can check if the API prefix is present but that will lead to the same issue that the responseTransforms had in #25 Possibility of "Smart" modeGood catch. I am okay with doing this in "force" mode. If anyone reports an issue we can revisit this functionality. |
Thanks 😉 |
data
key (rough POC for #51)data
key
Just a rough POC for #51 .
There are still some problems to resolve.