Skip to content

wqb2017/sendjs

Repository files navigation

sendjs

sendjs is a request library

Browser support

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔ 9+ ✔

install

npm install sendjs --save

import

import sendjs from 'sendjs';

Example

  • get methods sendjs.get(url,data,config).then().then().catch()
sendjs
  .get('/user', {
    age: 23
  })
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  })
  .then(function() {
    // always executed
  });
  • post methods sendjs.post(url,data,config).then().then().catch()
sendjs
  .post('/user', {
    age: 23
  })
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  })
  .then(function() {
    // always executed
  });
  • ajax methods sendjs.ajax(url,data,config).then().then().catch()
sendjs
  .ajax({
    data: {},
    //request type【post,get】
    type: 'get',
    async: true,
    //request server address
    baseUrl: '',
    //request header
    header: {
      'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'
    }
  })
  .then(function(response) {
    // handle success
    console.log(response);
  })
  .catch(function(error) {
    // handle error
    console.log(error);
  })
  .then(function() {
    // always executed
  });
  • default params set
sendjs.create({
  data: {},
  //request type【post,get】
  type: 'get',
  async: true,
  //request server address
  baseUrl: '',
  //request header
  header: {
    'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'
  }
});

sendjs API or Request method aliases

  • sendjs.create({...config...})
  • sendjs.get(url,data,config)
  • sendjs.post(url,data,config)
  • sendjs.ajax({...config...})
  • sendjs.downClient(url,data,config)
  • sendjs.upClient(url,data,config)

Request Config

  //default request params
  data: {},
  //request type【post,get】
  type: 'get',
  async:true,
  //request server address
  baseUrl: '',
  //request header
  header: {
    'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'
  },

License

MIT

About

http request

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages