Socket
Book a DemoInstallSign in
Socket

braker-client

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

braker-client

An client with circuit.

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

cloud-client

Usage

ResourceClient

import CloudClient from 'cloud-client';

import * as resourceInterface from './ResourceInterface';

const SERVICE_NAME = 'a-service';
const cClient = new CloudClient(SERVICE_NAME, resourceInterface);

//set health check.
cClient.setHealthCheck(resourceInterface.checkHealth);

//register http request api.
export default cClient.registerApi();

ResourceInterface

import rp from 'request-promise';

/**
 * Check the service's health status.
 */
export function checkHealth() {
    return rp({
        method: 'get',
        url: `/${SERVICE_NAME}/health`,
        headers: {
            'Content-Type': 'application/json'
        }
    });
}

export function getResource(id) {
    return rp({
        method: 'get',
        url: `/${SERVICE_NAME}/v1/resources/:id`,
        params: {id: id},
        headers: {
            'Content-Type': 'application/json'
        }
    });
}

You can use cloud client to invoke resource interface's function. example is

import resourceClient from './ResourceClient';

resourceClient.getResource(id);

API

new CloudClient(serviceName, interface, options)

serviceName

The service name.

interface

The key-value object for sending request.

options
  • logger: Default is console. you can use any other logger that implements logger.log function.
  • Other options param is the same as brakes

cClient.setHealthCheck(callback)

Set a callback, when the circuit is open, the callback will be used for checking the service's health status, if the status is ok, the circuit will close.

cClient.registerApi()

return cClient.registerApi();

Keywords

circuit

FAQs

Package last updated on 25 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts