Last active
October 16, 2019 02:23
-
-
Save ntucker/4822ec9d027015e3f1ee5f1fa2adbefe to your computer and use it in GitHub Desktop.
simple Resource class before normalization
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 PostResource { | |
readonly id: number | null = null; | |
readonly title: string = ''; | |
readonly body: string = ''; | |
constructor(args) { | |
Object.assign(this, args); | |
} | |
static async fetchDetail({ id }: { id: string }): PostResource { | |
const options = { | |
method: 'GET', | |
credentials: 'same-origin', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
}; | |
const url = `/post/${id}`; | |
const response = await (await fetch(url, options)).json(); | |
return new PostResource(response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment