Created
March 8, 2022 00:27
-
-
Save larkintuckerllc/20f03d2c7fa23c32d326343b9d9e5dc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MyPluginApi } from './types'; | |
import { DiscoveryApi } from '@backstage/core-plugin-api'; | |
export class MyPluginBackendClient implements MyPluginApi { | |
private readonly discoveryApi: DiscoveryApi; | |
constructor(options: { | |
discoveryApi: DiscoveryApi; | |
}) { | |
this.discoveryApi = options.discoveryApi; | |
} | |
private async handleResponse(response: Response): Promise<any> { | |
if (!response.ok) { | |
throw new Error(); | |
} | |
return await response.json(); | |
} | |
async getHealth(): Promise<{ status: string; }> { | |
const url = `${await this.discoveryApi.getBaseUrl('my-plugin')}/health`; | |
const response = await fetch(url, { | |
method: 'GET', | |
}); | |
return await this.handleResponse(response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment