Page updated Jan 16, 2024

Update data

PUT data

To create or update a todo item via the API endpoint:

1import { put } from 'aws-amplify/api';
2
3async function updateTodo() {
4 try {
5 const todo = { name: 'My first todo', message: 'Hello world!' };
6 const restOperation = put({
7 apiName: 'todo-api',
8 path: 'todo/1',
9 options: {
10 body: todo
11 }
12 });
13 const response = await restOperation.response;
14 console.log('PUT call succeeded: ', response);
15 } catch (e) {
16 console.log('PUT call failed: ', JSON.parse(e.response.body));
17 }
18}