2.2.1 • Published 2 months ago

@sliit-foss/service-connector v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@sliit-foss/service-connector

A microservice connector for node.js that uses axios under the hood and makes the process of debugging and logging API requests easier.

Installation

# using npm
npm install @sliit-foss/service-connector

# using yarn
yarn add @sliit-foss/service-connector

Usage

# using require
const serviceConnector = require("@sliit-foss/service-connector");

# using import
import serviceConnector from "@sliit-foss/service-connector";

Example

const connector = serviceConnector({
  // any configuration you want to pass to axios

  baseUrl: "http://localhost:3000",
  timeout: 1000,

  // optional module specific configurations

  service: "service-name",
  headerIntercepts: () => ({
    "x-api-key": "1234567890"
  }),
  loggable: (response) => {
    // do something with the response, both success and error
  }
});

// use the service connector as you would use axios
const response = await connector.get("/api/v1/users");

Resolver function

  • The connector has a resolver function that can be used to directly resolve the data from the API response if it comes in the following format.

    {
      "data": { ... }, // data coming from the API inside a nested data object
      "message": "Data retrieved successfully"
    }
  • The following will return the above data object directly without the need of calling response.data.data manually.

    const data = await connector.get("/api/v1/users").then(connector.resolve);
2.2.1

2 months ago

2.2.0

2 months ago

2.1.4

3 months ago

2.1.6

3 months ago

2.1.5

3 months ago

2.1.7

3 months ago

2.1.3

3 months ago

2.1.2

4 months ago

2.1.1

4 months ago

2.1.0

4 months ago

2.0.1

5 months ago

1.2.4

9 months ago

2.0.0

6 months ago

1.2.3-blizzard.0

11 months ago

1.2.3

11 months ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago