Skip to content

Instantly share code, notes, and snippets.

@mul14
Created March 24, 2017 13:02
Show Gist options
  • Save mul14/b3c7168ea2ba82f16153489117522bca to your computer and use it in GitHub Desktop.
Save mul14/b3c7168ea2ba82f16153489117522bca to your computer and use it in GitHub Desktop.
Example http request code
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