Last active
May 26, 2017 21:17
-
-
Save orbitbot/9e950029e9e8eba0bc8cd7710445df63 to your computer and use it in GitHub Desktop.
Ergonomic Mithril.js 1.x requests
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
// GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS | |
// data becomes querystring on GET requests | |
class Http { | |
constructor() { | |
let methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] | |
methods.forEach((method) => { | |
this[method] = (url, data, opts) => m.request(Object.assign({ method, url, data }, opts, this.eval(), this.defaults)) | |
}) | |
} | |
} | |
Http.prototype.defaults = {} | |
Http.prototype.eval = () => {} | |
m.http = new Http() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment