From 5d6b4a4675cb7985f886e922f501a4d88666b7e6 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 9 Nov 2023 13:15:49 +0100 Subject: [PATCH] fix: set Content-Type headers for requests with payload (#7) --- package.json | 2 +- src/Reflect.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 77e656c..7558a8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reflect-client", - "version": "1.1.1", + "version": "1.1.2", "main": "build/Reflect.js", "type": "module", "exports": { diff --git a/src/Reflect.ts b/src/Reflect.ts index 86bab18..ae8da71 100644 --- a/src/Reflect.ts +++ b/src/Reflect.ts @@ -18,9 +18,14 @@ export default class Client { } } + // Set request header + private setHeader(name, value): void { + return this.headers[name] = value; + } + // Set API key to use for all requests private setApiKey(key: string): void { - this.headers["Authorization"] = `Bearer ${key}`; + return this.setHeader("Authorization", `Bearer ${key}`); } // Get fully qualified URL to endpoint @@ -40,6 +45,7 @@ export default class Client { // JSON stringify and append body to request if provided and is not a GET request if (payload && method !== Method.GET) { + this.setHeader("Content-Type", "application/json"); options["body"] = JSON.stringify(payload); }