Skip to content

feat: add retry strategy for api-rest category #8295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function deleteItem() {
try {
const restOperation = del({
apiName: 'myRestApi',
path: 'items/1'
path: 'items/1',
});
await restOperation.response;
console.log('DELETE call succeeded');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ import { get } from 'aws-amplify/api';
async function getItem() {
try {
const restOperation = get({
apiName: 'myRestApi',
path: 'items'
apiName: 'myRestApi',
path: 'items'
options: {
retryStrategy: {
strategy: 'no-retry' // Overrides default retry strategy
},
}
});
const response = await restOperation.response;
console.log('GET call succeeded: ', response);
Expand All @@ -47,6 +52,10 @@ async function getItem() {
}
```

The `retryStrategy` can be configured with:
- `no-retry`: Single attempt, fails immediately on error
- `jittered-exponential-backoff`: Default strategy that retries with increasing delays, maximum 3 attempts

## Accessing response payload

You can consume the response payload by accessing the `body` property of the response object. Depending on the use case and the content type of the body, you can consume they payload in string, blob, or JSON.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function postItem() {
body: {
message: 'Mow the lawn'
}
}
},
});

const { body } = await restOperation.response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,24 @@ import outputs from '../amplify_outputs.json';

const amplifyConfig = parseAmplifyConfig(outputs);

Amplify.configure({
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
Amplify.configure(
{
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
},
},
});
{
API: {
REST: {
retryStrategy: {
strategy: 'no-retry' // Overrides default retry strategy
},
}
},
}
);
```
</InlineFilter>

Expand All @@ -251,13 +262,24 @@ import outputs from '@/amplify_outputs.json';

const amplifyConfig = parseAmplifyConfig(outputs);

Amplify.configure({
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
Amplify.configure(
{
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
},
},
});
{
API: {
REST: {
retryStrategy: {
strategy: 'no-retry' // Overrides default retry strategy
},
}
}
}
);
```
</InlineFilter>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,24 @@ import outputs from '../amplify_outputs.json';

const amplifyConfig = parseAmplifyConfig(outputs);

Amplify.configure({
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
Amplify.configure(
{
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
},
},
});
{
API: {
REST: {
retryStrategy: {
strategy: 'no-retry', // Overrides default retry strategy
},
}
}
}
);
```
</InlineFilter>

Expand All @@ -234,13 +245,24 @@ import outputs from '@/amplify_outputs.json';

const amplifyConfig = parseAmplifyConfig(outputs);

Amplify.configure({
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
},
});
Amplify.configure(
{
...amplifyConfig,
API: {
...amplifyConfig.API,
REST: outputs.custom.API,
},
},
{
API: {
REST: {
retryStrategy: {
strategy: 'no-retry' // Overrides default retry strategy
},
}
}
}
);
```
</InlineFilter>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function updateItems() {
path: 'items/1',
options: {
body: Item
}
},
});
const response = await restOperation.response;
console.log('PUT call succeeded: ', response);
Expand Down