-
-
Save wbobeirne/9f555b78d76cd16feb399b3a63aa168a 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
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