Skip to content

Instantly share code, notes, and snippets.

@oleh-zaporozhets
Last active November 11, 2020 09:25
Show Gist options
  • Select an option

  • Save oleh-zaporozhets/1b5ef896a7bb06d50db915a585a199b4 to your computer and use it in GitHub Desktop.

Select an option

Save oleh-zaporozhets/1b5ef896a7bb06d50db915a585a199b4 to your computer and use it in GitHub Desktop.
class MainApi extends HttpClient {
private static classInstance?: MainApi;
private constructor() {
super('https://api.awesome-site.com');
}
public static getInstance() {
if (!this.classInstance) {
this.classInstance = new MainApi();
}
return this.classInstance;
}
public getUsers = () => this.instance.get<User[]>('/users');
public getUser = (id: string) => this.instance.get<User>(`/users/${id}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment