Search code examples
androidamazon-web-servicesaws-amplifyrest

In AWS Amplify Android, why does Amplify.API.post() make a GET request?


So, I have a simple REST API implemented with AWS Amplify Android.

I create the plugin

try {
    Amplify.addPlugin(new AWSApiPlugin());
    Amplify.configure(getApplicationContext());
    Log.i("AmplifyGetStarted", "Amplify is ready for use!");
} catch (AmplifyException configurationFailure) {
    Log.e("AmplifyGetStarted", "Failed to configure Amplify", configurationFailure);
}

Then, when I do:

RestOptions addCard =
    new RestOptions("/cards/" + userid + "/" + card.id);
Amplify.API.post("apipacaward", addCard,
    restResponse -> Log.i(TAG, restResponse.getData().asString()),
    apiFailure -> Log.e("ApiQuickStart", apiFailure.getMessage(), apiFailure)
);

The response is:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Error</title>
  </head>
  <body>
    <pre>Cannot GET /cards/8f8cffd1-b0b4-4fc3-b39a-f0001d7981eb/397e3a23-c8e5-496b-8082-49267aa08510</pre>
  </body>
</html>

I am sure this is the response of a GET request to this endpoint because I've tested out in postman. Also, on postman, POST works just fine.


Solution

  • https://github.com/aws-amplify/amplify-android/issues/538

    So turns out it was a bug. There's a simple work-around just by adding an empty body