@aws-amplify/api-rest 4.0.1-console-preview.a1c533e.0 → 4.0.1-console-preview.23dc225.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apis/common/handler.js +14 -3
- package/lib/apis/common/internalPost.js +1 -1
- package/lib/apis/index.d.ts +178 -0
- package/lib/apis/index.js +178 -0
- package/lib/apis/server.d.ts +125 -0
- package/lib/apis/server.js +125 -0
- package/lib/errors/CanceledError.d.ts +17 -0
- package/lib/errors/CanceledError.js +35 -0
- package/lib/errors/index.d.ts +1 -1
- package/lib/errors/index.js +4 -4
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/server.d.ts +1 -1
- package/lib/server.js +2 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/utils/createCancellableOperation.js +10 -15
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/resolveApiUrl.js +4 -3
- package/lib/utils/resolveCredentials.d.ts +1 -6
- package/lib-esm/apis/common/handler.js +14 -3
- package/lib-esm/apis/common/internalPost.js +1 -1
- package/lib-esm/apis/index.d.ts +178 -0
- package/lib-esm/apis/index.js +178 -0
- package/lib-esm/apis/server.d.ts +125 -0
- package/lib-esm/apis/server.js +125 -0
- package/lib-esm/errors/CanceledError.d.ts +17 -0
- package/lib-esm/errors/CanceledError.js +31 -0
- package/lib-esm/errors/index.d.ts +1 -1
- package/lib-esm/errors/index.js +1 -1
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/server.d.ts +1 -1
- package/lib-esm/server.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +1 -1
- package/lib-esm/utils/createCancellableOperation.js +12 -17
- package/lib-esm/utils/index.d.ts +0 -1
- package/lib-esm/utils/index.js +0 -1
- package/lib-esm/utils/resolveApiUrl.js +4 -3
- package/lib-esm/utils/resolveCredentials.d.ts +1 -6
- package/package.json +5 -5
- package/src/apis/common/handler.ts +9 -2
- package/src/apis/common/internalPost.ts +1 -1
- package/src/apis/index.ts +179 -0
- package/src/apis/server.ts +126 -0
- package/src/errors/CanceledError.ts +33 -0
- package/src/errors/index.ts +1 -1
- package/src/index.ts +1 -1
- package/src/server.ts +1 -1
- package/src/types/index.ts +1 -1
- package/src/utils/createCancellableOperation.ts +5 -6
- package/src/utils/index.ts +0 -2
- package/src/utils/resolveApiUrl.ts +7 -3
- package/lib/errors/CancelledError.d.ts +0 -14
- package/lib/errors/CancelledError.js +0 -31
- package/lib/utils/polyfills/index.d.ts +0 -0
- package/lib/utils/polyfills/index.js +0 -4
- package/lib/utils/polyfills/index.native.d.ts +0 -1
- package/lib/utils/polyfills/index.native.js +0 -6
- package/lib-esm/errors/CancelledError.d.ts +0 -14
- package/lib-esm/errors/CancelledError.js +0 -27
- package/lib-esm/utils/polyfills/index.d.ts +0 -0
- package/lib-esm/utils/polyfills/index.js +0 -4
- package/lib-esm/utils/polyfills/index.native.d.ts +0 -1
- package/lib-esm/utils/polyfills/index.native.js +0 -4
- package/src/errors/CancelledError.ts +0 -26
- package/src/utils/polyfills/index.native.ts +0 -5
- package/src/utils/polyfills/index.ts +0 -4
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.resolveApiUrl = void 0;
|
|
6
6
|
var tslib_1 = require("tslib");
|
|
7
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
8
|
var errors_1 = require("../errors");
|
|
8
9
|
/**
|
|
9
10
|
* Resolve the REST API request URL by:
|
|
@@ -20,14 +21,14 @@ var resolveApiUrl = function (amplify, apiName, path, queryParams) {
|
|
|
20
21
|
var urlStr = (_d = (_c = (_b = (_a = amplify.getConfig()) === null || _a === void 0 ? void 0 : _a.API) === null || _b === void 0 ? void 0 : _b.REST) === null || _c === void 0 ? void 0 : _c[apiName]) === null || _d === void 0 ? void 0 : _d.endpoint;
|
|
21
22
|
(0, errors_1.assertValidationError)(!!urlStr, errors_1.RestApiValidationErrorCode.InvalidApiName);
|
|
22
23
|
try {
|
|
23
|
-
var url = new
|
|
24
|
+
var url = new utils_1.AmplifyUrl(urlStr + path);
|
|
24
25
|
if (queryParams) {
|
|
25
|
-
var mergedQueryParams_1 = new
|
|
26
|
+
var mergedQueryParams_1 = new utils_1.AmplifyUrlSearchParams(url.searchParams);
|
|
26
27
|
Object.entries(queryParams).forEach(function (_a) {
|
|
27
28
|
var _b = tslib_1.__read(_a, 2), key = _b[0], value = _b[1];
|
|
28
29
|
mergedQueryParams_1.set(key, value);
|
|
29
30
|
});
|
|
30
|
-
url.search = new
|
|
31
|
+
url.search = new utils_1.AmplifyUrlSearchParams(mergedQueryParams_1).toString();
|
|
31
32
|
}
|
|
32
33
|
return url;
|
|
33
34
|
}
|
|
@@ -2,9 +2,4 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export declare const resolveCredentials: (amplify: AmplifyClassV6) => Promise<
|
|
6
|
-
accessKeyId: string;
|
|
7
|
-
secretAccessKey: string;
|
|
8
|
-
sessionToken?: string | undefined;
|
|
9
|
-
expiration?: Date | undefined;
|
|
10
|
-
}>;
|
|
5
|
+
export declare const resolveCredentials: (amplify: AmplifyClassV6) => Promise<import("@aws-amplify/core/lib-esm/libraryUtils").AWSCredentials>;
|
|
@@ -13,7 +13,7 @@ import { normalizeHeaders } from '../../utils/normalizeHeaders';
|
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
15
15
|
export var transferHandler = function (amplify, options, signingServiceInfo) { return __awaiter(void 0, void 0, void 0, function () {
|
|
16
|
-
var url, method, headers, body, withCredentials, abortSignal, resolvedBody, resolvedHeaders, request, baseOptions, isIamAuthApplicable, signingInfoFromUrl, signingService, signingRegion, credentials;
|
|
16
|
+
var url, method, headers, body, withCredentials, abortSignal, resolvedBody, resolvedHeaders, request, baseOptions, isIamAuthApplicable, response, signingInfoFromUrl, signingService, signingRegion, credentials;
|
|
17
17
|
var _a, _b;
|
|
18
18
|
return __generator(this, function (_c) {
|
|
19
19
|
switch (_c.label) {
|
|
@@ -52,9 +52,20 @@ export var transferHandler = function (amplify, options, signingServiceInfo) { r
|
|
|
52
52
|
case 1:
|
|
53
53
|
credentials = _c.sent();
|
|
54
54
|
return [4 /*yield*/, authenticatedHandler(request, __assign(__assign({}, baseOptions), { credentials: credentials, region: signingRegion, service: signingService }))];
|
|
55
|
-
case 2:
|
|
55
|
+
case 2:
|
|
56
|
+
response = _c.sent();
|
|
57
|
+
return [3 /*break*/, 5];
|
|
56
58
|
case 3: return [4 /*yield*/, unauthenticatedHandler(request, __assign({}, baseOptions))];
|
|
57
|
-
case 4:
|
|
59
|
+
case 4:
|
|
60
|
+
response = _c.sent();
|
|
61
|
+
_c.label = 5;
|
|
62
|
+
case 5:
|
|
63
|
+
// Clean-up un-modeled properties from response.
|
|
64
|
+
return [2 /*return*/, {
|
|
65
|
+
statusCode: response.statusCode,
|
|
66
|
+
headers: response.headers,
|
|
67
|
+
body: response.body,
|
|
68
|
+
}];
|
|
58
69
|
}
|
|
59
70
|
});
|
|
60
71
|
}); };
|
|
@@ -42,7 +42,7 @@ export var cancel = function (promise, message) {
|
|
|
42
42
|
var controller = cancelTokenMap.get(promise);
|
|
43
43
|
if (controller) {
|
|
44
44
|
controller.abort(message);
|
|
45
|
-
if (controller.signal.reason !== message) {
|
|
45
|
+
if (message && controller.signal.reason !== message) {
|
|
46
46
|
// In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.
|
|
47
47
|
// @ts-expect-error reason is read-only property.
|
|
48
48
|
controller.signal['reason'] = message;
|
package/lib-esm/apis/index.d.ts
CHANGED
|
@@ -1,25 +1,203 @@
|
|
|
1
1
|
import { DeleteInput, DeleteOperation, GetInput, GetOperation, HeadInput, HeadOperation, PatchInput, PatchOperation, PostInput, PostOperation, PutInput, PutOperation } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* GET HTTP request
|
|
4
|
+
* @param {GetInput} input - Input for GET operation
|
|
5
|
+
* @returns {GetOperation} Operation for GET request
|
|
6
|
+
* @throws - {@link RestApiError}
|
|
7
|
+
* @example
|
|
8
|
+
* Send a GET request
|
|
9
|
+
* ```js
|
|
10
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
11
|
+
*
|
|
12
|
+
* const { body } = await get({
|
|
13
|
+
* apiName,
|
|
14
|
+
* path,
|
|
15
|
+
* options: {
|
|
16
|
+
* headers, // Optional, A map of custom header key/values
|
|
17
|
+
* body, // Optional, JSON object or FormData
|
|
18
|
+
* queryParams, // Optional, A map of query strings
|
|
19
|
+
* }
|
|
20
|
+
* }).response;
|
|
21
|
+
* const data = await body.json();
|
|
22
|
+
* ```
|
|
23
|
+
* @example
|
|
24
|
+
* Cancel a GET request
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
28
|
+
*
|
|
29
|
+
* const { response, cancel } = get({apiName, path, options});
|
|
30
|
+
* cancel(message);
|
|
31
|
+
* try {
|
|
32
|
+
* await response;
|
|
33
|
+
* } cache (e) {
|
|
34
|
+
* if (isCancelError(e)) {
|
|
35
|
+
* // handle request cancellation
|
|
36
|
+
* }
|
|
37
|
+
* //...
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
4
40
|
*/
|
|
5
41
|
export declare const get: (input: GetInput) => GetOperation;
|
|
6
42
|
/**
|
|
7
43
|
* POST HTTP request
|
|
44
|
+
* @param {PostInput} input - Input for POST operation
|
|
45
|
+
* @returns {PostOperation} Operation for POST request
|
|
46
|
+
* @throws - {@link RestApiError}
|
|
47
|
+
* @example
|
|
48
|
+
* Send a POST request
|
|
49
|
+
* ```js
|
|
50
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
51
|
+
*
|
|
52
|
+
* const { body } = await post({
|
|
53
|
+
* apiName,
|
|
54
|
+
* path,
|
|
55
|
+
* options: {
|
|
56
|
+
* headers, // Optional, A map of custom header key/values
|
|
57
|
+
* body, // Optional, JSON object or FormData
|
|
58
|
+
* queryParams, // Optional, A map of query strings
|
|
59
|
+
* }
|
|
60
|
+
* }).response;
|
|
61
|
+
* const data = await body.json();
|
|
62
|
+
* ```
|
|
63
|
+
* @example
|
|
64
|
+
* Cancel a POST request
|
|
65
|
+
*
|
|
66
|
+
* ```js
|
|
67
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
68
|
+
*
|
|
69
|
+
* const { response, cancel } = post({apiName, path, options});
|
|
70
|
+
* cancel(message);
|
|
71
|
+
* try {
|
|
72
|
+
* await response;
|
|
73
|
+
* } cache (e) {
|
|
74
|
+
* if (isCancelError(e)) {
|
|
75
|
+
* // handle request cancellation
|
|
76
|
+
* }
|
|
77
|
+
* //...
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
8
80
|
*/
|
|
9
81
|
export declare const post: (input: PostInput) => PostOperation;
|
|
10
82
|
/**
|
|
11
83
|
* PUT HTTP request
|
|
84
|
+
* @param {PutInput} input - Input for PUT operation
|
|
85
|
+
* @returns {PutOperation} Operation for PUT request
|
|
86
|
+
* @throws - {@link RestApiError}
|
|
87
|
+
* @example
|
|
88
|
+
* Send a PUT request
|
|
89
|
+
* ```js
|
|
90
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
91
|
+
*
|
|
92
|
+
* const { body } = await put({
|
|
93
|
+
* apiName,
|
|
94
|
+
* path,
|
|
95
|
+
* options: {
|
|
96
|
+
* headers, // Optional, A map of custom header key/values
|
|
97
|
+
* body, // Optional, JSON object or FormData
|
|
98
|
+
* queryParams, // Optional, A map of query strings
|
|
99
|
+
* }
|
|
100
|
+
* }).response;
|
|
101
|
+
* const data = await body.json();
|
|
102
|
+
* ```
|
|
103
|
+
* @example
|
|
104
|
+
* Cancel a PUT request
|
|
105
|
+
* ```js
|
|
106
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
107
|
+
*
|
|
108
|
+
* const { response, cancel } = put({apiName, path, options});
|
|
109
|
+
* cancel(message);
|
|
110
|
+
* try {
|
|
111
|
+
* await response;
|
|
112
|
+
* } cache (e) {
|
|
113
|
+
* if (isCancelError(e)) {
|
|
114
|
+
* // handle request cancellation
|
|
115
|
+
* }
|
|
116
|
+
* //...
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
12
119
|
*/
|
|
13
120
|
export declare const put: (input: PutInput) => PutOperation;
|
|
14
121
|
/**
|
|
15
122
|
* DELETE HTTP request
|
|
123
|
+
* @param {DeleteInput} input - Input for DELETE operation
|
|
124
|
+
* @returns {DeleteOperation} Operation for DELETE request
|
|
125
|
+
* @throws - {@link RestApiError}
|
|
126
|
+
* @example
|
|
127
|
+
* Send a DELETE request
|
|
128
|
+
* ```js
|
|
129
|
+
* import { del } from '@aws-amplify/api';
|
|
130
|
+
*
|
|
131
|
+
* const { statusCode } = await del({
|
|
132
|
+
* apiName,
|
|
133
|
+
* path,
|
|
134
|
+
* options: {
|
|
135
|
+
* headers, // Optional, A map of custom header key/values
|
|
136
|
+
* queryParams, // Optional, A map of query strings
|
|
137
|
+
* }
|
|
138
|
+
* }).response;
|
|
139
|
+
* ```
|
|
16
140
|
*/
|
|
17
141
|
export declare const del: (input: DeleteInput) => DeleteOperation;
|
|
18
142
|
/**
|
|
19
143
|
* HEAD HTTP request
|
|
144
|
+
* @param {HeadInput} input - Input for HEAD operation
|
|
145
|
+
* @returns {HeadOperation} Operation for HEAD request
|
|
146
|
+
* @throws - {@link RestApiError}
|
|
147
|
+
* @example
|
|
148
|
+
* Send a HEAD request
|
|
149
|
+
* ```js
|
|
150
|
+
* import { head, isCancelError } from '@aws-amplify/api';
|
|
151
|
+
*
|
|
152
|
+
* const { headers, statusCode } = await head({
|
|
153
|
+
* apiName,
|
|
154
|
+
* path,
|
|
155
|
+
* options: {
|
|
156
|
+
* headers, // Optional, A map of custom header key/values
|
|
157
|
+
* queryParams, // Optional, A map of query strings
|
|
158
|
+
* }
|
|
159
|
+
* }),response;
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
20
162
|
*/
|
|
21
163
|
export declare const head: (input: HeadInput) => HeadOperation;
|
|
22
164
|
/**
|
|
23
165
|
* PATCH HTTP request
|
|
166
|
+
* @param {PatchInput} input - Input for PATCH operation
|
|
167
|
+
* @returns {PatchOperation} Operation for PATCH request
|
|
168
|
+
* @throws - {@link RestApiError}
|
|
169
|
+
* @example
|
|
170
|
+
* Send a PATCH request
|
|
171
|
+
* ```js
|
|
172
|
+
* import { patch } from '@aws-amplify/api';
|
|
173
|
+
*
|
|
174
|
+
* const { body } = await patch({
|
|
175
|
+
* apiName,
|
|
176
|
+
* path,
|
|
177
|
+
* options: {
|
|
178
|
+
* headers, // Optional, A map of custom header key/values
|
|
179
|
+
* body, // Optional, JSON object or FormData
|
|
180
|
+
* queryParams, // Optional, A map of query strings
|
|
181
|
+
* }
|
|
182
|
+
* }).response;
|
|
183
|
+
* const data = await body.json();
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* Cancel a PATCH request
|
|
188
|
+
* ```js
|
|
189
|
+
* import { patch, isCancelError } from '@aws-amplify/api';
|
|
190
|
+
*
|
|
191
|
+
* const { response, cancel } = patch({apiName, path, options});
|
|
192
|
+
* cancel(message);
|
|
193
|
+
* try {
|
|
194
|
+
* await response;
|
|
195
|
+
* } cache (e) {
|
|
196
|
+
* if (isCancelError(e)) {
|
|
197
|
+
* // handle request cancellation
|
|
198
|
+
* }
|
|
199
|
+
* //...
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
24
202
|
*/
|
|
25
203
|
export declare const patch: (input: PatchInput) => PatchOperation;
|
package/lib-esm/apis/index.js
CHANGED
|
@@ -4,32 +4,210 @@ import { Amplify } from '@aws-amplify/core';
|
|
|
4
4
|
import { get as commonGet, post as commonPost, put as commonPut, del as commonDel, head as commonHead, patch as commonPatch, } from './common/publicApis';
|
|
5
5
|
/**
|
|
6
6
|
* GET HTTP request
|
|
7
|
+
* @param {GetInput} input - Input for GET operation
|
|
8
|
+
* @returns {GetOperation} Operation for GET request
|
|
9
|
+
* @throws - {@link RestApiError}
|
|
10
|
+
* @example
|
|
11
|
+
* Send a GET request
|
|
12
|
+
* ```js
|
|
13
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
14
|
+
*
|
|
15
|
+
* const { body } = await get({
|
|
16
|
+
* apiName,
|
|
17
|
+
* path,
|
|
18
|
+
* options: {
|
|
19
|
+
* headers, // Optional, A map of custom header key/values
|
|
20
|
+
* body, // Optional, JSON object or FormData
|
|
21
|
+
* queryParams, // Optional, A map of query strings
|
|
22
|
+
* }
|
|
23
|
+
* }).response;
|
|
24
|
+
* const data = await body.json();
|
|
25
|
+
* ```
|
|
26
|
+
* @example
|
|
27
|
+
* Cancel a GET request
|
|
28
|
+
*
|
|
29
|
+
* ```js
|
|
30
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
31
|
+
*
|
|
32
|
+
* const { response, cancel } = get({apiName, path, options});
|
|
33
|
+
* cancel(message);
|
|
34
|
+
* try {
|
|
35
|
+
* await response;
|
|
36
|
+
* } cache (e) {
|
|
37
|
+
* if (isCancelError(e)) {
|
|
38
|
+
* // handle request cancellation
|
|
39
|
+
* }
|
|
40
|
+
* //...
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
7
43
|
*/
|
|
8
44
|
export var get = function (input) { return commonGet(Amplify, input); };
|
|
9
45
|
/**
|
|
10
46
|
* POST HTTP request
|
|
47
|
+
* @param {PostInput} input - Input for POST operation
|
|
48
|
+
* @returns {PostOperation} Operation for POST request
|
|
49
|
+
* @throws - {@link RestApiError}
|
|
50
|
+
* @example
|
|
51
|
+
* Send a POST request
|
|
52
|
+
* ```js
|
|
53
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
54
|
+
*
|
|
55
|
+
* const { body } = await post({
|
|
56
|
+
* apiName,
|
|
57
|
+
* path,
|
|
58
|
+
* options: {
|
|
59
|
+
* headers, // Optional, A map of custom header key/values
|
|
60
|
+
* body, // Optional, JSON object or FormData
|
|
61
|
+
* queryParams, // Optional, A map of query strings
|
|
62
|
+
* }
|
|
63
|
+
* }).response;
|
|
64
|
+
* const data = await body.json();
|
|
65
|
+
* ```
|
|
66
|
+
* @example
|
|
67
|
+
* Cancel a POST request
|
|
68
|
+
*
|
|
69
|
+
* ```js
|
|
70
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
71
|
+
*
|
|
72
|
+
* const { response, cancel } = post({apiName, path, options});
|
|
73
|
+
* cancel(message);
|
|
74
|
+
* try {
|
|
75
|
+
* await response;
|
|
76
|
+
* } cache (e) {
|
|
77
|
+
* if (isCancelError(e)) {
|
|
78
|
+
* // handle request cancellation
|
|
79
|
+
* }
|
|
80
|
+
* //...
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
11
83
|
*/
|
|
12
84
|
export var post = function (input) {
|
|
13
85
|
return commonPost(Amplify, input);
|
|
14
86
|
};
|
|
15
87
|
/**
|
|
16
88
|
* PUT HTTP request
|
|
89
|
+
* @param {PutInput} input - Input for PUT operation
|
|
90
|
+
* @returns {PutOperation} Operation for PUT request
|
|
91
|
+
* @throws - {@link RestApiError}
|
|
92
|
+
* @example
|
|
93
|
+
* Send a PUT request
|
|
94
|
+
* ```js
|
|
95
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
96
|
+
*
|
|
97
|
+
* const { body } = await put({
|
|
98
|
+
* apiName,
|
|
99
|
+
* path,
|
|
100
|
+
* options: {
|
|
101
|
+
* headers, // Optional, A map of custom header key/values
|
|
102
|
+
* body, // Optional, JSON object or FormData
|
|
103
|
+
* queryParams, // Optional, A map of query strings
|
|
104
|
+
* }
|
|
105
|
+
* }).response;
|
|
106
|
+
* const data = await body.json();
|
|
107
|
+
* ```
|
|
108
|
+
* @example
|
|
109
|
+
* Cancel a PUT request
|
|
110
|
+
* ```js
|
|
111
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
112
|
+
*
|
|
113
|
+
* const { response, cancel } = put({apiName, path, options});
|
|
114
|
+
* cancel(message);
|
|
115
|
+
* try {
|
|
116
|
+
* await response;
|
|
117
|
+
* } cache (e) {
|
|
118
|
+
* if (isCancelError(e)) {
|
|
119
|
+
* // handle request cancellation
|
|
120
|
+
* }
|
|
121
|
+
* //...
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
17
124
|
*/
|
|
18
125
|
export var put = function (input) { return commonPut(Amplify, input); };
|
|
19
126
|
/**
|
|
20
127
|
* DELETE HTTP request
|
|
128
|
+
* @param {DeleteInput} input - Input for DELETE operation
|
|
129
|
+
* @returns {DeleteOperation} Operation for DELETE request
|
|
130
|
+
* @throws - {@link RestApiError}
|
|
131
|
+
* @example
|
|
132
|
+
* Send a DELETE request
|
|
133
|
+
* ```js
|
|
134
|
+
* import { del } from '@aws-amplify/api';
|
|
135
|
+
*
|
|
136
|
+
* const { statusCode } = await del({
|
|
137
|
+
* apiName,
|
|
138
|
+
* path,
|
|
139
|
+
* options: {
|
|
140
|
+
* headers, // Optional, A map of custom header key/values
|
|
141
|
+
* queryParams, // Optional, A map of query strings
|
|
142
|
+
* }
|
|
143
|
+
* }).response;
|
|
144
|
+
* ```
|
|
21
145
|
*/
|
|
22
146
|
export var del = function (input) {
|
|
23
147
|
return commonDel(Amplify, input);
|
|
24
148
|
};
|
|
25
149
|
/**
|
|
26
150
|
* HEAD HTTP request
|
|
151
|
+
* @param {HeadInput} input - Input for HEAD operation
|
|
152
|
+
* @returns {HeadOperation} Operation for HEAD request
|
|
153
|
+
* @throws - {@link RestApiError}
|
|
154
|
+
* @example
|
|
155
|
+
* Send a HEAD request
|
|
156
|
+
* ```js
|
|
157
|
+
* import { head, isCancelError } from '@aws-amplify/api';
|
|
158
|
+
*
|
|
159
|
+
* const { headers, statusCode } = await head({
|
|
160
|
+
* apiName,
|
|
161
|
+
* path,
|
|
162
|
+
* options: {
|
|
163
|
+
* headers, // Optional, A map of custom header key/values
|
|
164
|
+
* queryParams, // Optional, A map of query strings
|
|
165
|
+
* }
|
|
166
|
+
* }),response;
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
27
169
|
*/
|
|
28
170
|
export var head = function (input) {
|
|
29
171
|
return commonHead(Amplify, input);
|
|
30
172
|
};
|
|
31
173
|
/**
|
|
32
174
|
* PATCH HTTP request
|
|
175
|
+
* @param {PatchInput} input - Input for PATCH operation
|
|
176
|
+
* @returns {PatchOperation} Operation for PATCH request
|
|
177
|
+
* @throws - {@link RestApiError}
|
|
178
|
+
* @example
|
|
179
|
+
* Send a PATCH request
|
|
180
|
+
* ```js
|
|
181
|
+
* import { patch } from '@aws-amplify/api';
|
|
182
|
+
*
|
|
183
|
+
* const { body } = await patch({
|
|
184
|
+
* apiName,
|
|
185
|
+
* path,
|
|
186
|
+
* options: {
|
|
187
|
+
* headers, // Optional, A map of custom header key/values
|
|
188
|
+
* body, // Optional, JSON object or FormData
|
|
189
|
+
* queryParams, // Optional, A map of query strings
|
|
190
|
+
* }
|
|
191
|
+
* }).response;
|
|
192
|
+
* const data = await body.json();
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* Cancel a PATCH request
|
|
197
|
+
* ```js
|
|
198
|
+
* import { patch, isCancelError } from '@aws-amplify/api';
|
|
199
|
+
*
|
|
200
|
+
* const { response, cancel } = patch({apiName, path, options});
|
|
201
|
+
* cancel(message);
|
|
202
|
+
* try {
|
|
203
|
+
* await response;
|
|
204
|
+
* } cache (e) {
|
|
205
|
+
* if (isCancelError(e)) {
|
|
206
|
+
* // handle request cancellation
|
|
207
|
+
* }
|
|
208
|
+
* //...
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
33
211
|
*/
|
|
34
212
|
export var patch = function (input) {
|
|
35
213
|
return commonPatch(Amplify, input);
|
package/lib-esm/apis/server.d.ts
CHANGED
|
@@ -2,25 +2,150 @@ import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
|
2
2
|
import { DeleteInput, DeleteOperation, GetInput, GetOperation, HeadInput, HeadOperation, PatchInput, PatchOperation, PostInput, PostOperation, PutInput, PutOperation } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* GET HTTP request (server-side)
|
|
5
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
6
|
+
* @param {GetInput} input - Input for GET operation.
|
|
7
|
+
* @throws - {@link RestApiError}
|
|
8
|
+
* @example
|
|
9
|
+
* Send a GET request
|
|
10
|
+
* ```js
|
|
11
|
+
* import { get } from 'aws-amplify/api/server';
|
|
12
|
+
* //...
|
|
13
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
14
|
+
* nextServerContext: { request, response },
|
|
15
|
+
* operation: async (contextSpec) => {
|
|
16
|
+
* try {
|
|
17
|
+
* const { body } = await get(contextSpec, input).response;
|
|
18
|
+
* return await body.json();
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* console.log(error);
|
|
21
|
+
* return false;
|
|
22
|
+
* }
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
* @see {@link clientGet}
|
|
5
27
|
*/
|
|
6
28
|
export declare const get: (contextSpec: AmplifyServer.ContextSpec, input: GetInput) => GetOperation;
|
|
7
29
|
/**
|
|
8
30
|
* POST HTTP request (server-side)
|
|
31
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
32
|
+
* @param {PostInput} input - Input for POST operation.
|
|
33
|
+
* @throws - {@link RestApiError}
|
|
34
|
+
* @example
|
|
35
|
+
* Send a POST request
|
|
36
|
+
* ```js
|
|
37
|
+
* import { post } from 'aws-amplify/api/server';
|
|
38
|
+
* //...
|
|
39
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
40
|
+
* nextServerContext: { request, response },
|
|
41
|
+
* operation: async (contextSpec) => {
|
|
42
|
+
* try {
|
|
43
|
+
* const { body } = await post(contextSpec, input).response;
|
|
44
|
+
* return await body.json();
|
|
45
|
+
* } catch (error) {
|
|
46
|
+
* console.log(error);
|
|
47
|
+
* return false;
|
|
48
|
+
* }
|
|
49
|
+
* },
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
9
52
|
*/
|
|
10
53
|
export declare const post: (contextSpec: AmplifyServer.ContextSpec, input: PostInput) => PostOperation;
|
|
11
54
|
/**
|
|
12
55
|
* PUT HTTP request (server-side)
|
|
56
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
57
|
+
* @param {PutInput} input - Input for PUT operation.
|
|
58
|
+
* @throws - {@link RestApiError}
|
|
59
|
+
* @example
|
|
60
|
+
* Send a PUT request
|
|
61
|
+
* ```js
|
|
62
|
+
* import { put } from 'aws-amplify/api/server';
|
|
63
|
+
* //...
|
|
64
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
65
|
+
* nextServerContext: { request, response },
|
|
66
|
+
* operation: async (contextSpec) => {
|
|
67
|
+
* try {
|
|
68
|
+
* const { body } = await put(contextSpec, input).response;
|
|
69
|
+
* return await body.json();
|
|
70
|
+
* } catch (error) {
|
|
71
|
+
* console.log(error);
|
|
72
|
+
* return false;
|
|
73
|
+
* }
|
|
74
|
+
* },
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
13
77
|
*/
|
|
14
78
|
export declare const put: (contextSpec: AmplifyServer.ContextSpec, input: PutInput) => PutOperation;
|
|
15
79
|
/**
|
|
16
80
|
* DELETE HTTP request (server-side)
|
|
81
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
82
|
+
* @param {DeleteInput} input - Input for DELETE operation.
|
|
83
|
+
* @throws - {@link RestApiError}
|
|
84
|
+
* @example
|
|
85
|
+
* Send a DELETE request
|
|
86
|
+
* ```js
|
|
87
|
+
* import { del } from 'aws-amplify/api/server';
|
|
88
|
+
* //...
|
|
89
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
90
|
+
* nextServerContext: { request, response },
|
|
91
|
+
* operation: async (contextSpec) => {
|
|
92
|
+
* try {
|
|
93
|
+
* const { headers } = await del(contextSpec, input).response;
|
|
94
|
+
* } catch (error) {
|
|
95
|
+
* console.log(error);
|
|
96
|
+
* return false;
|
|
97
|
+
* }
|
|
98
|
+
* },
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
17
101
|
*/
|
|
18
102
|
export declare const del: (contextSpec: AmplifyServer.ContextSpec, input: DeleteInput) => DeleteOperation;
|
|
19
103
|
/**
|
|
20
104
|
* HEAD HTTP request (server-side)
|
|
105
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
106
|
+
* @param {HeadInput} input - Input for HEAD operation.
|
|
107
|
+
* @throws - {@link RestApiError}
|
|
108
|
+
* @example
|
|
109
|
+
* Send a HEAD request
|
|
110
|
+
* ```js
|
|
111
|
+
* import { head } from 'aws-amplify/api/server';
|
|
112
|
+
* //...
|
|
113
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
114
|
+
* nextServerContext: { request, response },
|
|
115
|
+
* operation: async (contextSpec) => {
|
|
116
|
+
* try {
|
|
117
|
+
* const { headers } = await head(contextSpec, input).response;
|
|
118
|
+
* } catch (error) {
|
|
119
|
+
* console.log(error);
|
|
120
|
+
* return false;
|
|
121
|
+
* }
|
|
122
|
+
* },
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
21
125
|
*/
|
|
22
126
|
export declare const head: (contextSpec: AmplifyServer.ContextSpec, input: HeadInput) => HeadOperation;
|
|
23
127
|
/**
|
|
24
128
|
* PATCH HTTP request (server-side)
|
|
129
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
130
|
+
* @param {PatchInput} input - Input for PATCH operation.
|
|
131
|
+
* @throws - {@link RestApiError}
|
|
132
|
+
* @example
|
|
133
|
+
* Send a PATCH request
|
|
134
|
+
* ```js
|
|
135
|
+
* import { patch } from 'aws-amplify/api/server';
|
|
136
|
+
* //...
|
|
137
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
138
|
+
* nextServerContext: { request, response },
|
|
139
|
+
* operation: async (contextSpec) => {
|
|
140
|
+
* try {
|
|
141
|
+
* const { body } = await patch(contextSpec, input).response;
|
|
142
|
+
* return await body.json();
|
|
143
|
+
* } catch (error) {
|
|
144
|
+
* console.log(error);
|
|
145
|
+
* return false;
|
|
146
|
+
* }
|
|
147
|
+
* },
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
25
150
|
*/
|
|
26
151
|
export declare const patch: (contextSpec: AmplifyServer.ContextSpec, input: PatchInput) => PatchOperation;
|