wip: 2023-09-20T12:53:34+0200 (1695207214)

This commit is contained in:
Victor Westerlund 2023-09-20 17:10:09 +02:00
parent a7855f5631
commit 7d3cd3c6fe
2 changed files with 10 additions and 2 deletions

View file

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

View file

@ -1,5 +1,8 @@
import { Method } from "./Method.js"; import { Method } from "./Method.js";
// Export Method as importable directly from the Reflect.js ESM
export { Method };
// Connect to a Reflect API instance over HTTP // Connect to a Reflect API instance over HTTP
export default class Client { export default class Client {
private url: string; private url: string;
@ -19,6 +22,11 @@ export default class Client {
this.headers["Authentication"] = `Bearer ${key}`; this.headers["Authentication"] = `Bearer ${key}`;
} }
// Get fully qualified URL to endpoint
private getEndpoint(endpoint: string): string {
return this.url + endpoint;
}
// Call a Reflect API endpoint with method and optional payload // Call a Reflect API endpoint with method and optional payload
public async call(endpoint: string, method: Method, payload: any = null): Promise<Response> { public async call(endpoint: string, method: Method, payload: any = null): Promise<Response> {
const options: object = { const options: object = {
@ -32,6 +40,6 @@ export default class Client {
} }
// Fetch and return Response object // Fetch and return Response object
return await fetch(endpoint, options); return await fetch(this.getEndpoint(endpoint), options);
} }
} }