* 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)
| 39 | * @returns {import('@aws-appsync/utils').HTTPRequest} the request |
| 40 | */ |
| 41 | function 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 | } |