@copropr/base-service
Base Service ============= #### The base service to be extended by api's. It is mostly a wrapper to [request-promise](https://github.com/request/request-promise).
Last updated 2 years ago by cmseguin .
ISC · Original npm · Tarball · package.json
$ cnpm install @copropr/base-service 
SYNC missed versions from official npm registry.

Base Service

The base service to be extended by api's. It is mostly a wrapper to request-promise.

Installation

# NPM
$ npm i -S @copropr/base-service

# Yarn
$ yarn add @copropr/base-service

Usage

// Commonjs
const BaseService = require('@copropr/base-service').default

// ES6 module way
import BaseService from '@copropr/base-service'

class TestService extends BaseService {
  constructor (args) {
    super(args)
    // Extend the constructor here
  }

  async interceptRequest (request) {
    // Modify, log, or manipulate the request
    return request
  }

  async interceptResponse (response) {
    // Modify, log, or manipulate the response
    return response
  }
}

const service = new TestService({
  baseUrl: 'https://httpstat.us/',
  resolveWithFullResponse: true
})

const response = await service.get('/200')

Note: Make sure the interceptRequest & interceptResponse return a promise or are using async/await to make sure any async operation that would modify the request or response are correctly intercepted.

API

get method

A wrapper to request-promise get method

example:

const response = service.get('/uri', options)

post method

A wrapper to request-promise post method

example:

const response = service.post('/uri', options)

put method

A wrapper to request-promise put method

example:

const response = service.put('/uri', options)

patch method

A wrapper to request-promise patch method

example:

const response = service.patch('/uri', options)

delete method

A wrapper to request-promise delete method

example:

const response = service.delete('/uri', options)

Current Tags

  • 0.0.1                                ...           latest (2 years ago)

1 Versions

  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |