0.1.4 • Published 3 years ago

service-api v0.1.4

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

service api tool

ajax request and response a promise

install
npm install service-api --save
  import service from 'service-api'

  // could set config
  service.config({
    showLoading: () => { to show loading },
    hideLoading: () => { to hide loading },
    dealError: (error) => {
      deal some error
    },
    checkStatus: (resp) => { // default code == 200 is success request, u can override method for your project
      return resp.code === 200
    }
  })

  service.get(path, {key: 'value'}, {
    context: document.body // with a loading at the html node
  }).then((resp) => {

  }).catch((error) => {

  })

  service.post(path, {key: 'value'}, {
    context: document.body
  }).then((resp) => {
    
  }).catch((error) => {

  })

  let defered = service.post(path, {key: 'value'}, {
    context: document.body
  })

  defered.then(() => {

  })

  // to cancel a ajax
  defered.cancel()

  // you can set responseType on the third arguments
  service.get(path, {key: 'value'}, {
    context: document.body,
    responseType: 'arraybuffer',
    timeout: 30000 // config timeout ms, default 60000ms
  }).then((resp) => {

  }).catch((error) => {

  })

  // to clear requests which has send and not received, like to a new page
  service.clear()
0.1.4

3 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

2.0.0

7 years ago