mirror of
https://codeberg.org/reflect/reflect-client-js.git
synced 2025-09-14 05:53:42 +02:00
wip: 2023-09-20T12:53:34+0200 (1695207214)
This commit is contained in:
parent
a7855f5631
commit
7d3cd3c6fe
2 changed files with 10 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "reflect-client",
|
||||
"version": "1.1.0-beta.0",
|
||||
"version": "1.1.0-beta.1",
|
||||
"main": "build/Reflect.js",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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
|
||||
export default class Client {
|
||||
private url: string;
|
||||
|
@ -19,6 +22,11 @@ export default class Client {
|
|||
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
|
||||
public async call(endpoint: string, method: Method, payload: any = null): Promise<Response> {
|
||||
const options: object = {
|
||||
|
@ -32,6 +40,6 @@ export default class Client {
|
|||
}
|
||||
|
||||
// Fetch and return Response object
|
||||
return await fetch(endpoint, options);
|
||||
return await fetch(this.getEndpoint(endpoint), options);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue