Skip to content

Instantly share code, notes, and snippets.

@wbobeirne
Last active May 29, 2019 18:14
Show Gist options
  • Save wbobeirne/9f555b78d76cd16feb399b3a63aa168a to your computer and use it in GitHub Desktop.
Save wbobeirne/9f555b78d76cd16feb399b3a63aa168a to your computer and use it in GitHub Desktop.
class API {
url: string;
constructor(url: string) {
this.url = url;
}
// Public methods
submitPost(name: string, content: string) {
return this.request<{ post: Post; invoice: string; }>(
'POST',
'/posts',
{ name, content },
);
}
getPosts() {
return this.request<Post[]>('GET', '/posts');
}
getPost(id: number) {
return this.request<Post>('GET', `/posts/${id}`);
}
/* ... */
}
// Export a default API that points at the API_PATH environment variable
export default new API(process.env.API_PATH as string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment