amplify-js
amplify-js copied to clipboard
Signer.sign({body:"hello"}, {method:"POST"}) should use `body` attribute like fetch()
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues and discussions.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Typescript page, with React, and I am using the Signer.sign() library directly (Sorry not using the full Amplify toolset)
import { Signer } from 'aws-amplify';
Describe the bug
- Run this code
Signer.sign({body:"hello"}, {method:"POST"}); // <---- Notice body attribute, where API docs use data.
- output:
headers: Content-Length: 0
Expected behavior
One possible solution:
headers: Content-Length: 5
Another possible solution:
throw "attribute `body` found in Signer, but `data` is missing. Please use attribute `data`"
Reproduction steps
create-react-app import { Signer } from 'aws-amplify'; Signer.sign({body:"hello"}, {method:"POST"})
Code Snippet
// Put your code below this line.
Log output
// Put your logs below this line
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
@maxerbubba I was looking for clarification in the exact code you ran to get the error. As far as I can tell your code seems to be a more reduced version of code sent to the sign method is it possible to send a more detailed code snippet as sending just the code you sent with the two objects results in an error due to missing information, or some more detail in exactly what you would like implemented. Also could you provide some clarification on the second possible solutionthrow "attribute `body` found in Signer, but `data` is missing. Please use attribute `body`"
on what you would like implemented for this solution to work.
Whoops, I meant to put "data". (I edited the message above)
throw "attribute `body` found in Signer, but `data` is missing. Please use attribute `data`"
I was frustrated. This is just a convenience, to compare to similar libraries. I was initially using fetch(), and then was trying to switch to AmplifyJS signer, and my old code still had body
.
- For example, fetch() uses
body
attribute https://developer.mozilla.org/en-US/docs/Web/API/fetch - requests uses
data
attribute - curl linux command uses
--data
attribute - Amplify uses:
data
attribute https://aws-amplify.github.io/amplify-js/api/classes/signer.html
Adding a little type checking on the input object would be nice for developers to find bugs faster.
@maxerbubba So, if I understand correctly, you want to ensure that a body sent in the request object will be treated the same as sending data. Or you want an error thrown when there is a body in the request object but not a data attribute. Is there a preference between the two, or am I not getting what you want correct?
That is correct. I have no prference. I imagine there would be debate about which is the best attribute, and it would be painful to change the API contract, but an error message would be easy to implement and give developers all of the benefits.
On Wed, Jul 20, 2022 at 1:31 PM ahilashsasidharan @.***> wrote:
@maxerbubba https://github.com/maxerbubba So, if I understand correctly, you want to ensure that a body sent in the request object will be treated the same as sending data. Or you want an error thrown when there is a body in the request object but not a data attribute. Is there a preference between the two, or am I not getting what you want correct?
— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-js/issues/9863#issuecomment-1190727007, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7KYTQOZST6AWXP4LV6XATVVBOYVANCNFSM5U5NU6WQ . You are receiving this because you were mentioned.Message ID: @.***>
Closing this as it has been fixed by https://github.com/aws-amplify/amplify-js/pull/10137
Thank you, @amehi0index ! 🚀