Compare commits

..

No commits in common. "master" and "1.1.0" have entirely different histories.

2 changed files with 5 additions and 15 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "reflect-client", "name": "reflect-client",
"version": "1.1.2", "version": "1.1.0",
"main": "build/Reflect.js", "main": "build/Reflect.js",
"type": "module", "type": "module",
"exports": { "exports": {

View file

@ -9,8 +9,7 @@ export default class Client {
private headers: object = {}; private headers: object = {};
constructor(url: string, key: string|null = null) { constructor(url: string, key: string|null = null) {
// Append tailing slash if omitted from URL string this.url = url;
this.url = url.substring(url.length - 1) === "/" ? url : url + "/";
// Use API key with requests if defined // Use API key with requests if defined
if (key) { if (key) {
@ -18,21 +17,13 @@ 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 // Set API key to use for all requests
private setApiKey(key: string): void { private setApiKey(key: string): void {
return this.setHeader("Authorization", `Bearer ${key}`); this.headers["Authorization"] = `Bearer ${key}`;
} }
// Get fully qualified URL to endpoint // Get fully qualified URL to endpoint
private getEndpoint(endpoint: string): string { private getEndpoint(endpoint: string): string {
// Remove leading slash if provided for pathname. It's already set on the domain name
endpoint = endpoint.substring(0, 1) !== "/" ? endpoint : endpoint.substring(1, endpoint.length);
return this.url + endpoint; return this.url + endpoint;
} }
@ -43,9 +34,8 @@ export default class Client {
headers: this.headers headers: this.headers
} }
// JSON stringify and append body to request if provided and is not a GET request // JSON stringify and append body to request if provided
if (payload && method !== Method.GET) { if (payload) {
this.setHeader("Content-Type", "application/json");
options["body"] = JSON.stringify(payload); options["body"] = JSON.stringify(payload);
} }