Update data
PUT requests
To update an item via the API endpoint:
RestOptions options = RestOptions.builder() .addPath("/todo/1") .addBody("{\"name\":\"Mow the lawn\"}".getBytes()) .build();
Amplify.API.put(options, response -> Log.i("MyAmplifyApp", "PUT succeeded: " + response), error -> Log.e("MyAmplifyApp", "PUT failed.", error));
val request = RestOptions.builder() .addPath("/todo/1") .addBody("{\"name\":\"Mow the lawn\"}".toByteArray()) .build()
Amplify.API.put(request, { Log.i("MyAmplifyApp", "PUT succeeded: $it") }, { Log.e("MyAmplifyApp", "PUT failed", it) })
val request = RestOptions.builder() .addPath("/todo/1") .addBody(JSONObject() .put("name", "Mow the lawn") .toString() .toByteArray()) .build()try { val response = Amplify.API.put(request) Log.i("MyAmplifyApp", "PUT succeeded: $response")} catch (error: ApiException) { Log.e("MyAmplifyApp", "PUT failed", it)}
RestOptions options = RestOptions.builder() .addPath("/todo/1") .addBody("{\"name\":\"Mow the lawn\"}".getBytes()) .build();
RxAmplify.API.put(options) .subscribe( response -> Log.i("MyAmplifyApp", "PUT succeeded: " + response), error -> Log.e("MyAmplifyApp", "PUT failed.", error) );