@aws-amplify/api-rest 4.0.1-console-preview.a1c533e.0 → 4.0.1-console-preview.f7f118b.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
|
@@ -16,7 +16,7 @@ var normalizeHeaders_1 = require("../../utils/normalizeHeaders");
|
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
18
|
var transferHandler = function (amplify, options, signingServiceInfo) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
19
|
-
var url, method, headers, body, withCredentials, abortSignal, resolvedBody, resolvedHeaders, request, baseOptions, isIamAuthApplicable, signingInfoFromUrl, signingService, signingRegion, credentials;
|
|
19
|
+
var url, method, headers, body, withCredentials, abortSignal, resolvedBody, resolvedHeaders, request, baseOptions, isIamAuthApplicable, response, signingInfoFromUrl, signingService, signingRegion, credentials;
|
|
20
20
|
var _a, _b;
|
|
21
21
|
return tslib_1.__generator(this, function (_c) {
|
|
22
22
|
switch (_c.label) {
|
|
@@ -55,9 +55,20 @@ var transferHandler = function (amplify, options, signingServiceInfo) { return t
|
|
|
55
55
|
case 1:
|
|
56
56
|
credentials = _c.sent();
|
|
57
57
|
return [4 /*yield*/, (0, aws_client_utils_1.authenticatedHandler)(request, tslib_1.__assign(tslib_1.__assign({}, baseOptions), { credentials: credentials, region: signingRegion, service: signingService }))];
|
|
58
|
-
case 2:
|
|
58
|
+
case 2:
|
|
59
|
+
response = _c.sent();
|
|
60
|
+
return [3 /*break*/, 5];
|
|
59
61
|
case 3: return [4 /*yield*/, (0, aws_client_utils_1.unauthenticatedHandler)(request, tslib_1.__assign({}, baseOptions))];
|
|
60
|
-
case 4:
|
|
62
|
+
case 4:
|
|
63
|
+
response = _c.sent();
|
|
64
|
+
_c.label = 5;
|
|
65
|
+
case 5:
|
|
66
|
+
// Clean-up un-modeled properties from response.
|
|
67
|
+
return [2 /*return*/, {
|
|
68
|
+
statusCode: response.statusCode,
|
|
69
|
+
headers: response.headers,
|
|
70
|
+
body: response.body,
|
|
71
|
+
}];
|
|
61
72
|
}
|
|
62
73
|
});
|
|
63
74
|
}); };
|
|
@@ -46,7 +46,7 @@ var cancel = function (promise, message) {
|
|
|
46
46
|
var controller = cancelTokenMap.get(promise);
|
|
47
47
|
if (controller) {
|
|
48
48
|
controller.abort(message);
|
|
49
|
-
if (controller.signal.reason !== message) {
|
|
49
|
+
if (message && controller.signal.reason !== message) {
|
|
50
50
|
// In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.
|
|
51
51
|
// @ts-expect-error reason is read-only property.
|
|
52
52
|
controller.signal['reason'] = message;
|
package/lib/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/apis/index.js
CHANGED
|
@@ -7,11 +7,83 @@ var core_1 = require("@aws-amplify/core");
|
|
|
7
7
|
var publicApis_1 = require("./common/publicApis");
|
|
8
8
|
/**
|
|
9
9
|
* GET HTTP request
|
|
10
|
+
* @param {GetInput} input - Input for GET operation
|
|
11
|
+
* @returns {GetOperation} Operation for GET request
|
|
12
|
+
* @throws - {@link RestApiError}
|
|
13
|
+
* @example
|
|
14
|
+
* Send a GET request
|
|
15
|
+
* ```js
|
|
16
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
17
|
+
*
|
|
18
|
+
* const { body } = await get({
|
|
19
|
+
* apiName,
|
|
20
|
+
* path,
|
|
21
|
+
* options: {
|
|
22
|
+
* headers, // Optional, A map of custom header key/values
|
|
23
|
+
* body, // Optional, JSON object or FormData
|
|
24
|
+
* queryParams, // Optional, A map of query strings
|
|
25
|
+
* }
|
|
26
|
+
* }).response;
|
|
27
|
+
* const data = await body.json();
|
|
28
|
+
* ```
|
|
29
|
+
* @example
|
|
30
|
+
* Cancel a GET request
|
|
31
|
+
*
|
|
32
|
+
* ```js
|
|
33
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
34
|
+
*
|
|
35
|
+
* const { response, cancel } = get({apiName, path, options});
|
|
36
|
+
* cancel(message);
|
|
37
|
+
* try {
|
|
38
|
+
* await response;
|
|
39
|
+
* } cache (e) {
|
|
40
|
+
* if (isCancelError(e)) {
|
|
41
|
+
* // handle request cancellation
|
|
42
|
+
* }
|
|
43
|
+
* //...
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
10
46
|
*/
|
|
11
47
|
var get = function (input) { return (0, publicApis_1.get)(core_1.Amplify, input); };
|
|
12
48
|
exports.get = get;
|
|
13
49
|
/**
|
|
14
50
|
* POST HTTP request
|
|
51
|
+
* @param {PostInput} input - Input for POST operation
|
|
52
|
+
* @returns {PostOperation} Operation for POST request
|
|
53
|
+
* @throws - {@link RestApiError}
|
|
54
|
+
* @example
|
|
55
|
+
* Send a POST request
|
|
56
|
+
* ```js
|
|
57
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
58
|
+
*
|
|
59
|
+
* const { body } = await post({
|
|
60
|
+
* apiName,
|
|
61
|
+
* path,
|
|
62
|
+
* options: {
|
|
63
|
+
* headers, // Optional, A map of custom header key/values
|
|
64
|
+
* body, // Optional, JSON object or FormData
|
|
65
|
+
* queryParams, // Optional, A map of query strings
|
|
66
|
+
* }
|
|
67
|
+
* }).response;
|
|
68
|
+
* const data = await body.json();
|
|
69
|
+
* ```
|
|
70
|
+
* @example
|
|
71
|
+
* Cancel a POST request
|
|
72
|
+
*
|
|
73
|
+
* ```js
|
|
74
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
75
|
+
*
|
|
76
|
+
* const { response, cancel } = post({apiName, path, options});
|
|
77
|
+
* cancel(message);
|
|
78
|
+
* try {
|
|
79
|
+
* await response;
|
|
80
|
+
* } cache (e) {
|
|
81
|
+
* if (isCancelError(e)) {
|
|
82
|
+
* // handle request cancellation
|
|
83
|
+
* }
|
|
84
|
+
* //...
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
15
87
|
*/
|
|
16
88
|
var post = function (input) {
|
|
17
89
|
return (0, publicApis_1.post)(core_1.Amplify, input);
|
|
@@ -19,11 +91,63 @@ var post = function (input) {
|
|
|
19
91
|
exports.post = post;
|
|
20
92
|
/**
|
|
21
93
|
* PUT HTTP request
|
|
94
|
+
* @param {PutInput} input - Input for PUT operation
|
|
95
|
+
* @returns {PutOperation} Operation for PUT request
|
|
96
|
+
* @throws - {@link RestApiError}
|
|
97
|
+
* @example
|
|
98
|
+
* Send a PUT request
|
|
99
|
+
* ```js
|
|
100
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
101
|
+
*
|
|
102
|
+
* const { body } = await put({
|
|
103
|
+
* apiName,
|
|
104
|
+
* path,
|
|
105
|
+
* options: {
|
|
106
|
+
* headers, // Optional, A map of custom header key/values
|
|
107
|
+
* body, // Optional, JSON object or FormData
|
|
108
|
+
* queryParams, // Optional, A map of query strings
|
|
109
|
+
* }
|
|
110
|
+
* }).response;
|
|
111
|
+
* const data = await body.json();
|
|
112
|
+
* ```
|
|
113
|
+
* @example
|
|
114
|
+
* Cancel a PUT request
|
|
115
|
+
* ```js
|
|
116
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
117
|
+
*
|
|
118
|
+
* const { response, cancel } = put({apiName, path, options});
|
|
119
|
+
* cancel(message);
|
|
120
|
+
* try {
|
|
121
|
+
* await response;
|
|
122
|
+
* } cache (e) {
|
|
123
|
+
* if (isCancelError(e)) {
|
|
124
|
+
* // handle request cancellation
|
|
125
|
+
* }
|
|
126
|
+
* //...
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
22
129
|
*/
|
|
23
130
|
var put = function (input) { return (0, publicApis_1.put)(core_1.Amplify, input); };
|
|
24
131
|
exports.put = put;
|
|
25
132
|
/**
|
|
26
133
|
* DELETE HTTP request
|
|
134
|
+
* @param {DeleteInput} input - Input for DELETE operation
|
|
135
|
+
* @returns {DeleteOperation} Operation for DELETE request
|
|
136
|
+
* @throws - {@link RestApiError}
|
|
137
|
+
* @example
|
|
138
|
+
* Send a DELETE request
|
|
139
|
+
* ```js
|
|
140
|
+
* import { del } from '@aws-amplify/api';
|
|
141
|
+
*
|
|
142
|
+
* const { statusCode } = await del({
|
|
143
|
+
* apiName,
|
|
144
|
+
* path,
|
|
145
|
+
* options: {
|
|
146
|
+
* headers, // Optional, A map of custom header key/values
|
|
147
|
+
* queryParams, // Optional, A map of query strings
|
|
148
|
+
* }
|
|
149
|
+
* }).response;
|
|
150
|
+
* ```
|
|
27
151
|
*/
|
|
28
152
|
var del = function (input) {
|
|
29
153
|
return (0, publicApis_1.del)(core_1.Amplify, input);
|
|
@@ -31,6 +155,24 @@ var del = function (input) {
|
|
|
31
155
|
exports.del = del;
|
|
32
156
|
/**
|
|
33
157
|
* HEAD HTTP request
|
|
158
|
+
* @param {HeadInput} input - Input for HEAD operation
|
|
159
|
+
* @returns {HeadOperation} Operation for HEAD request
|
|
160
|
+
* @throws - {@link RestApiError}
|
|
161
|
+
* @example
|
|
162
|
+
* Send a HEAD request
|
|
163
|
+
* ```js
|
|
164
|
+
* import { head, isCancelError } from '@aws-amplify/api';
|
|
165
|
+
*
|
|
166
|
+
* const { headers, statusCode } = await head({
|
|
167
|
+
* apiName,
|
|
168
|
+
* path,
|
|
169
|
+
* options: {
|
|
170
|
+
* headers, // Optional, A map of custom header key/values
|
|
171
|
+
* queryParams, // Optional, A map of query strings
|
|
172
|
+
* }
|
|
173
|
+
* }),response;
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
34
176
|
*/
|
|
35
177
|
var head = function (input) {
|
|
36
178
|
return (0, publicApis_1.head)(core_1.Amplify, input);
|
|
@@ -38,6 +180,42 @@ var head = function (input) {
|
|
|
38
180
|
exports.head = head;
|
|
39
181
|
/**
|
|
40
182
|
* PATCH HTTP request
|
|
183
|
+
* @param {PatchInput} input - Input for PATCH operation
|
|
184
|
+
* @returns {PatchOperation} Operation for PATCH request
|
|
185
|
+
* @throws - {@link RestApiError}
|
|
186
|
+
* @example
|
|
187
|
+
* Send a PATCH request
|
|
188
|
+
* ```js
|
|
189
|
+
* import { patch } from '@aws-amplify/api';
|
|
190
|
+
*
|
|
191
|
+
* const { body } = await patch({
|
|
192
|
+
* apiName,
|
|
193
|
+
* path,
|
|
194
|
+
* options: {
|
|
195
|
+
* headers, // Optional, A map of custom header key/values
|
|
196
|
+
* body, // Optional, JSON object or FormData
|
|
197
|
+
* queryParams, // Optional, A map of query strings
|
|
198
|
+
* }
|
|
199
|
+
* }).response;
|
|
200
|
+
* const data = await body.json();
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* Cancel a PATCH request
|
|
205
|
+
* ```js
|
|
206
|
+
* import { patch, isCancelError } from '@aws-amplify/api';
|
|
207
|
+
*
|
|
208
|
+
* const { response, cancel } = patch({apiName, path, options});
|
|
209
|
+
* cancel(message);
|
|
210
|
+
* try {
|
|
211
|
+
* await response;
|
|
212
|
+
* } cache (e) {
|
|
213
|
+
* if (isCancelError(e)) {
|
|
214
|
+
* // handle request cancellation
|
|
215
|
+
* }
|
|
216
|
+
* //...
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
41
219
|
*/
|
|
42
220
|
var patch = function (input) {
|
|
43
221
|
return (0, publicApis_1.patch)(core_1.Amplify, input);
|
package/lib/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;
|