New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

asd-io

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asd-io

generic io toolchain both for browser and node

  • 1.0.6
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

io

Promise based HTTP client for the browser and node.js wrapper axios and add jsonp support

Installing

Using npm:

$ npm install asd-io

Test

//test in browser with karma
$ npm run test
//test in node with mocha
$ npm run node-test

Build

$ npm run build

Example

Performing a request

io[method](url,data,success,fail,config)
io.get(
  // request url
  '/user',
  // optional request query data or request data
  {ID: 12345},
  //handle business success
  function (data) {
    console.log(data);
  },
  //handle business fail when code is not false value or server error
  function (error) {
    console.log(error)
  },
  //extra config  or axios config
  {
    // use application/json with modern api
    emulateJSON:false
  })
  //handle success in promise
  .then(function (data) {
    console.log(data);
  })
  //handle error in promise
  .catch(function (error) {
    console.log(error);
    //error.$ is origin error throw by axios
    console.log(error.$);
  });

response

response data is formatted as

{
  code:0,
  data:"data from server"
  message:"message from server"
}

response error is formatted as

{
  code:"error code",
  data:"error data from server",
  message:"error message from server",
  $:axios throw error
}

config

see https://github.com/mzabriskie/axios#request-config

{
    // use application/json with modern api
    emulateJSON:false
}

axios

//the axios instance is in io.fetch and origin axios is in io.axios
//if you want to use interceptors
// request interceptor
io.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// response interceptor
io.interceptors.response.use(function (response) {
    // Do something with response data
    return response;
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });

instance

create instance with config

const instance = io.create({
  baseURL:"http://www.analysys.cn",
  emulateJSON:false
})

defaults

set default config in all instance

io.config.emulateJSON = false

for more detail see http://git.analysys.cn/npm/io/tree/master/test

FAQs

Package last updated on 24 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc