# service-api

> ajax tool

Latest version **0.1.4** (published 2021-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install service-api
pnpm add service-api
yarn add service-api
bun add service-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2021-01-21 |
| First published | 2018-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | zhangshaolong |
| Maintainers | zhangshaolongjj |
| Keywords | ajax, async, sync, request, api |

## Links

- npm: https://www.npmjs.com/package/service-api
- Repository: https://github.com/zhangshaolong/service-api
- Homepage: https://github.com/zhangshaolong/service-api#readme
- Issues: https://github.com/zhangshaolong/service-api/issues
- npm.io page: https://npm.io/package/service-api

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.1

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2021-01-21
- 0.1.3 — 2019-10-13
- 0.1.2 — 2019-08-23
- 0.1.1 — 2019-07-01
- 0.1.0 — 2019-06-08
- 0.0.9 — 2019-06-08
- 0.0.8 — 2018-12-13
- 0.0.7 — 2018-12-05
- 0.0.6 — 2018-12-05
- 0.0.5 — 2018-10-10
- 0.0.4 — 2018-09-21
- 0.0.3 — 2018-09-14
- 0.0.2 — 2018-09-12
- 0.0.1 — 2018-09-04

## README

# service api tool
ajax request and response a promise

    install
    npm install service-api --save

```javascript
  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()
```

---
_Source: https://npm.io/package/service-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
