Skip to content

Instantly share code, notes, and snippets.

@orbitbot
Last active May 26, 2017 21:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save orbitbot/9e950029e9e8eba0bc8cd7710445df63 to your computer and use it in GitHub Desktop.
Save orbitbot/9e950029e9e8eba0bc8cd7710445df63 to your computer and use it in GitHub Desktop.
Ergonomic Mithril.js 1.x requests
// 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