diff --git a/README.md b/README.md index 8fcd8d55..25eaeb01 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ const Webflow = require('webflow-api'); // Initialize the API const api = new Webflow({ token: 'api-token' }); +// Initialize the API without CORS mode +const apiNoCors = new Webflow({ token: 'api-token', fetchOpts: { mode: undefined }}); + // Fetch a site api.site({ siteId: '580e63e98c9a982ac9b8b741' }).then(site => console.log(site)); ``` @@ -32,6 +35,7 @@ The `Webflow` constructor takes several options to initialize the API client: * `token` - the API token **(required)** * `version` - the version of the API you wish to use (optional) +* `fetchOpts` - an option to override `fetch` options All of the API methods are documented in the [API documentation](https://developers.webflow.com). diff --git a/index.d.ts b/index.d.ts index 3b2d566d..a304fb74 100644 --- a/index.d.ts +++ b/index.d.ts @@ -178,6 +178,7 @@ declare namespace Webflow { token: string; endpoint?: string; version?: string; + fetchOpts?: RequestInit; } namespace WebflowApiModel { diff --git a/src/Webflow.js b/src/Webflow.js index e5e8a49c..a0201bca 100644 --- a/src/Webflow.js +++ b/src/Webflow.js @@ -52,7 +52,7 @@ const responseHandler = (res) => }); export default class Webflow { - constructor({ endpoint = DEFAULT_ENDPOINT, token, version = "1.0.0" } = {}) { + constructor({ endpoint = DEFAULT_ENDPOINT, token, version = "1.0.0", fetchOpts = {} } = {}) { if (!token) throw buildRequiredArgError("token"); this.responseWrapper = new ResponseWrapper(this); @@ -76,6 +76,7 @@ export default class Webflow { method, headers: this.headers, mode: "cors", + ...fetchOpts, }; if (data) {