Skip to content

Commit a2ec6ab

Browse files
authored
feat: add retry strategy for api-rest category (#8295)
1 parent c201ceb commit a2ec6ab

File tree

6 files changed

+83
-30
lines changed

6 files changed

+83
-30
lines changed

Diff for: src/pages/[platform]/build-a-backend/add-aws-services/rest-api/delete-data/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function deleteItem() {
3737
try {
3838
const restOperation = del({
3939
apiName: 'myRestApi',
40-
path: 'items/1'
40+
path: 'items/1',
4141
});
4242
await restOperation.response;
4343
console.log('DELETE call succeeded');

Diff for: src/pages/[platform]/build-a-backend/add-aws-services/rest-api/fetch-data/index.mdx

+11-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ import { get } from 'aws-amplify/api';
3636
async function getItem() {
3737
try {
3838
const restOperation = get({
39-
apiName: 'myRestApi',
40-
path: 'items'
39+
apiName: 'myRestApi',
40+
path: 'items'
41+
options: {
42+
retryStrategy: {
43+
strategy: 'no-retry' // Overrides default retry strategy
44+
},
45+
}
4146
});
4247
const response = await restOperation.response;
4348
console.log('GET call succeeded: ', response);
@@ -47,6 +52,10 @@ async function getItem() {
4752
}
4853
```
4954

55+
The `retryStrategy` can be configured with:
56+
- `no-retry`: Single attempt, fails immediately on error
57+
- `jittered-exponential-backoff`: Default strategy that retries with increasing delays, maximum 3 attempts
58+
5059
## Accessing response payload
5160

5261
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.

Diff for: src/pages/[platform]/build-a-backend/add-aws-services/rest-api/post-data/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function postItem() {
4242
body: {
4343
message: 'Mow the lawn'
4444
}
45-
}
45+
},
4646
});
4747

4848
const { body } = await restOperation.response;

Diff for: src/pages/[platform]/build-a-backend/add-aws-services/rest-api/set-up-http-api/index.mdx

+34-12
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,24 @@ import outputs from '../amplify_outputs.json';
233233

234234
const amplifyConfig = parseAmplifyConfig(outputs);
235235

236-
Amplify.configure({
237-
...amplifyConfig,
238-
API: {
239-
...amplifyConfig.API,
240-
REST: outputs.custom.API,
236+
Amplify.configure(
237+
{
238+
...amplifyConfig,
239+
API: {
240+
...amplifyConfig.API,
241+
REST: outputs.custom.API,
242+
},
241243
},
242-
});
244+
{
245+
API: {
246+
REST: {
247+
retryStrategy: {
248+
strategy: 'no-retry' // Overrides default retry strategy
249+
},
250+
}
251+
},
252+
}
253+
);
243254
```
244255
</InlineFilter>
245256

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

252263
const amplifyConfig = parseAmplifyConfig(outputs);
253264

254-
Amplify.configure({
255-
...amplifyConfig,
256-
API: {
257-
...amplifyConfig.API,
258-
REST: outputs.custom.API,
265+
Amplify.configure(
266+
{
267+
...amplifyConfig,
268+
API: {
269+
...amplifyConfig.API,
270+
REST: outputs.custom.API,
271+
},
259272
},
260-
});
273+
{
274+
API: {
275+
REST: {
276+
retryStrategy: {
277+
strategy: 'no-retry' // Overrides default retry strategy
278+
},
279+
}
280+
}
281+
}
282+
);
261283
```
262284
</InlineFilter>
263285

Diff for: src/pages/[platform]/build-a-backend/add-aws-services/rest-api/set-up-rest-api/index.mdx

+35-13
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,24 @@ import outputs from '../amplify_outputs.json';
216216

217217
const amplifyConfig = parseAmplifyConfig(outputs);
218218

219-
Amplify.configure({
220-
...amplifyConfig,
221-
API: {
222-
...amplifyConfig.API,
223-
REST: outputs.custom.API,
219+
Amplify.configure(
220+
{
221+
...amplifyConfig,
222+
API: {
223+
...amplifyConfig.API,
224+
REST: outputs.custom.API,
225+
},
224226
},
225-
});
227+
{
228+
API: {
229+
REST: {
230+
retryStrategy: {
231+
strategy: 'no-retry', // Overrides default retry strategy
232+
},
233+
}
234+
}
235+
}
236+
);
226237
```
227238
</InlineFilter>
228239

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

235246
const amplifyConfig = parseAmplifyConfig(outputs);
236247

237-
Amplify.configure({
238-
...amplifyConfig,
239-
API: {
240-
...amplifyConfig.API,
241-
REST: outputs.custom.API,
242-
},
243-
});
248+
Amplify.configure(
249+
{
250+
...amplifyConfig,
251+
API: {
252+
...amplifyConfig.API,
253+
REST: outputs.custom.API,
254+
},
255+
},
256+
{
257+
API: {
258+
REST: {
259+
retryStrategy: {
260+
strategy: 'no-retry' // Overrides default retry strategy
261+
},
262+
}
263+
}
264+
}
265+
);
244266
```
245267
</InlineFilter>
246268

Diff for: src/pages/[platform]/build-a-backend/add-aws-services/rest-api/update-data/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function updateItems() {
4141
path: 'items/1',
4242
options: {
4343
body: Item
44-
}
44+
},
4545
});
4646
const response = await restOperation.response;
4747
console.log('PUT call succeeded: ', response);

0 commit comments

Comments
 (0)