Created
March 24, 2017 13:02
-
-
Save mul14/b3c7168ea2ba82f16153489117522bca to your computer and use it in GitHub Desktop.
Example http request code
This file contains hidden or 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 Http { | |
static send(method, url) { | |
const request = new Request(url, {method}) | |
return fetch(request) | |
.then(response => response.json()) | |
.then(json => json) | |
} | |
static get(url) { | |
return Promise.resolve(this.send('GET', url)) | |
} | |
static post(url) { | |
return Promise.resolve(this.send('POST', url)) | |
} | |
static delete(url) { | |
return Promise.resolve(this.send('DELETE', url)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment