MCPcopy Create free account
hub / github.com/aws-samples/aws-appsync-resolver-samples / fetch

Function fetch

samples/http/forward.js:41–58  ·  view source on GitHub ↗

* Sends an HTTP request * @param {string} resourcePath path of the request * @param {Object} [options] values to publish * @param {'PUT' | 'POST' | 'GET' | 'DELETE' | 'PATCH'} [options.method] the request method * @param {Object. } [options.headers] the request headers * @param {

(resourcePath, options)

Source from the content-addressed store, hash-verified

39 * @returns {import('@aws-appsync/utils').HTTPRequest} the request
40 */
41function fetch(resourcePath, options) {
42 const { method = 'GET', headers, body: _body, query = {} } = options;
43 const [path, params] = resourcePath.split('?');
44 console.log('params > ', params);
45 if (params && params.length) {
46 params.split('&').forEach((param) => {
47 console.log('param > ', param);
48 const [key, value] = param.split('=');
49 query[key] = value;
50 });
51 }
52 const body = typeof _body === 'object' ? JSON.stringify(_body) : _body;
53 return {
54 resourcePath: path,
55 method,
56 params: { headers, query, body },
57 };
58}

Callers 1

requestFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected