Page updated Nov 14, 2023

Update data

PUT data

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

import { put } from 'aws-amplify/api'; async function updateTodo() { try { const todo = { name: 'My first todo', message: 'Hello world!' }; const restOperation = put({ apiName: 'todo-api', path: 'todo/1', options: { body: todo } }); const response = await restOperation.response; console.log('PUT call succeeded: ', response); } catch (err) { console.log('PUT call failed: ', err); } }
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 (err) {
16 console.log('PUT call failed: ', err);
17 }
18}