1.2.4 • Published 5 years ago

isomorphic-unfetch-api-service v1.2.4

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

Why To be able to make server/client side requests with the same service, with common headers preset, and a standard output data shape.

Installation

npm install isomorphic-unfetch-api-service

Usage

const ApiService = require(`isomorphic-unfetch-api-service`); 
const apiServiceInstance = new ApiService()
apiServiceInstance.get('/api/thing')
.then(res => {
  // res is a JSON object/array
})
.catch(error => {
  // error is a message 
})
;

If the url needs a token or you are calling the same host, you can set it by extending the ApiService extendPath method:

const ApiService = require(`isomorphic-unfetch-api-service`);

class PathwaysApiService extends ApiService {

  extendPath = path => {
    const delimiter = path.indexOf(`?`) === -1 ? `?` : `&`;
    return `${process.env.API_URI}${path}${delimiter}token=${process.env.API_TOKEN}`;
  }

}
module.exports = new PathwaysApiService()
;
1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago