{"version":3,"file":"fetchWrapper-1c328951.js","sources":["../../../src/js/modules/fetch-wrapper.js"],"sourcesContent":["/**\n * A helper to make working with standard JS Fetch a little simpler.\n * @module fetch-wrapper\n */\nexport default class FetchWrapper {\n\t/**\n\t * @param {URL} baseUrl - baseUrl is the \"root\" URL for whichever API you're using\n\t */\n\tconstructor(baseURL) {\n\t\tthis.baseURL = baseURL;\n\t}\n\n\t/**\n\t * Issue a GET request on the provided endpoint, expects a JSON response.\n\t * @param {*} endpoint\n\t * @returns {JSON}\n\t */\n\tget(endpoint) {\n\t\treturn fetch(this.baseURL + endpoint)\n\t\t\t.then(response => response.json());\n\t}\n\n\t/**\n\t * Issue a GET request on the provided endpoint, returns the raw text.\n\t * @param {*} endpoint\n\t * @returns {text}\n\t */\n\tgetHtml(endpoint) {\n\t\treturn fetch(this.baseURL + endpoint)\n\t\t\t.then(response => response.text());\n\t}\n\n\t/**\n\t * Issue a PUT request to the endpoint\n\t * @param {*} endpoint - The API endpoint to PUT to\n\t * @param {*} body - The information being sent\n\t * @returns {string} - HTTP status code\n\t */\n\tput(endpoint, body) {\n\t\treturn this.#send(\"put\", endpoint, body);\n\t}\n\n\t/**\n\t * Issue a POST request to the endpoint\n\t * @param {*} endpoint - The API endpoint to PUT to\n\t * @param {*} body - The information being sent\n\t * @returns {string} - HTTP status code\n\t */\n\tpost(endpoint, body) {\n\t\treturn this.#send(\"post\", endpoint, body);\n\t}\n\n\t/**\n\t * Issue a DELETE request to the endpoint\n\t * @param {*} endpoint - The API endpoint to PUT to\n\t * @param {*} body - The information being sent\n\t * @returns {string} - HTTP status code\n\t */\n\tdelete(endpoint, body) {\n\t\treturn this.#send(\"delete\", endpoint, body);\n\t}\n\n\t#send(method, endpoint, body) {\n\t\treturn fetch(this.baseURL + endpoint, {\n\t\t\tmethod,\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\"\n\t\t\t},\n\t\t\tbody: JSON.stringify(body)\n\t\t}).then(\n\t\t\tresponse => response.json()\n\t\t);\n\t}\n}\n\n// Use:\n//\n// import FetchWrapper from './fetch-wrapper.js';\n// const API = new FetchWrapper('https://baseUrlHere');\n// API.get( endpoint );\n// API.put( endpoint, { key: value });\n"],"names":["_send","send_fn","FetchWrapper","baseURL","__privateAdd","endpoint","response","body","__privateMethod","method"],"mappings":"wPAAA,IAAAA,EAAAC,EAIe,MAAMC,CAAa,CAIjC,YAAYC,EAAS,CAsDrBC,EAAA,KAAAJ,GArDC,KAAK,QAAUG,CACf,CAOD,IAAIE,EAAU,CACb,OAAO,MAAM,KAAK,QAAUA,CAAQ,EAClC,KAAKC,GAAYA,EAAS,KAAM,CAAA,CAClC,CAOD,QAAQD,EAAU,CACjB,OAAO,MAAM,KAAK,QAAUA,CAAQ,EAClC,KAAKC,GAAYA,EAAS,KAAM,CAAA,CAClC,CAQD,IAAID,EAAUE,EAAM,CACnB,OAAOC,EAAA,KAAKR,EAAAC,GAAL,UAAW,MAAOI,EAAUE,EACnC,CAQD,KAAKF,EAAUE,EAAM,CACpB,OAAOC,EAAA,KAAKR,EAAAC,GAAL,UAAW,OAAQI,EAAUE,EACpC,CAQD,OAAOF,EAAUE,EAAM,CACtB,OAAOC,EAAA,KAAKR,EAAAC,GAAL,UAAW,SAAUI,EAAUE,EACtC,CAaF,CAXCP,EAAA,YAAAC,EAAK,SAACQ,EAAQJ,EAAUE,EAAM,CAC7B,OAAO,MAAM,KAAK,QAAUF,EAAU,CACrC,OAAAI,EACA,QAAS,CACR,eAAgB,kBAChB,EACD,KAAM,KAAK,UAAUF,CAAI,CACzB,CAAA,EAAE,KACFD,GAAYA,EAAS,KAAM,CAC9B,CACE"}