Skip to content

Instantly share code, notes, and snippets.

@rosd89
Created August 25, 2017 05:08
Show Gist options
  • Save rosd89/0e94cab2a65b24f4fb53dce86fb37dc1 to your computer and use it in GitHub Desktop.
Save rosd89/0e94cab2a65b24f4fb53dce86fb37dc1 to your computer and use it in GitHub Desktop.
const axios = require('axios');
const querystring = require('querystring');
const headers = {'Content-Type': 'application/x-www-form-urlencoded'};
/**
* ajax http get request
*
* @param url
* @param params
*/
exports.get = (url, params) => axios.get(url, {params});
/**
* ajax http post request
*
* @param url
* @param params
*/
exports.post = (url, params) => axios.post(url, querystring.stringify(params), {headers});
/**
* ajax http put request
*
* @param url
* @param params
*/
exports.put = (url, params) => axios.put(url, querystring.stringify(params), {headers});
/**
* ajax http patch request
*
* @param url
* @param params
*/
exports.patch = (url, params) => axios.patch(url, querystring.stringify(params), {headers});
/**
* ajax http delete request
*
* @param url
* @param params
*/
exports.delete = (url, params) => axios.delete(url, {params});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment