Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated May 3, 2024

Post data

POST Requests

Send a POST request with a JSON body.

import { post } from 'aws-amplify/api';
async function postItem() {
try {
const restOperation = post({
apiName: 'myRestApi',
path: 'items',
options: {
body: {
message: 'Mow the lawn'
}
}
});
const { body } = await restOperation.response;
const response = await body.json();
console.log('POST call succeeded');
console.log(response);
} catch (error) {
console.log('POST call failed: ', JSON.parse(error.response.body));
}
}