Skip to content

Commit

Permalink
feat: Add $withBaseUrl method
Browse files Browse the repository at this point in the history
  • Loading branch information
andertun committed Feb 15, 2024
1 parent eb0d62f commit 86714ae
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { BaseRestClient } from '@kapeta/sdk-rest';
const SERVICE_TYPE = 'rest';

export class RestClient extends BaseRestClient {

private readonly resourceName: string;
private ready: boolean = false;

Expand All @@ -20,7 +19,7 @@ export class RestClient extends BaseRestClient {
* @param autoInit If true, the client will automatically initialise itself when the config provider is ready.
*/

public constructor(resourceName: string, autoInit:boolean = true) {
public constructor(resourceName: string, autoInit: boolean = true) {
super(fetch, `http://${resourceName.toLowerCase()}`);
this.resourceName = resourceName;

Expand All @@ -36,6 +35,15 @@ export class RestClient extends BaseRestClient {
return this;
}

public $withBaseUrl(baseUrl: string) {
this.$baseUrl = baseUrl;

if (!this.$baseUrl.endsWith('/')) {
this.$baseUrl += '/';
}

return this;
}

/**
* Called automatically during startup sequence.
Expand All @@ -57,5 +65,4 @@ export class RestClient extends BaseRestClient {

console.log('REST client ready for %s --> %s', this.resourceName, this.$baseUrl);
}

}

0 comments on commit 86714ae

Please sign in to comment.