0.2.0 • Published 5 years ago

@ptenn/service-client v0.2.0

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

service-client

Installation

Run yarn add @ptenn/service-client or npm add @ptenn/service-client.

Usage

To set up a config provider, use the following as a guideline:

import { ServiceClient } from '@ptenn/service-client';

class MyClient extends ServiceClient {
    constructor(config) {
        this.host = config.host;
        this.headers = config.headers;
        this.query = config.query;
        // ...
    }

    methodName() {
        return this.get({
            uri: '/endpoint',
        });
    }
}

To create a basic client, just create a config and instantiate a new ServiceClient as follows:

// config/myServiceClient.ts
import { Config, ExtractValueFn } from '@ptenn/config-provider';

export interface MyServiceClientConfig {
    baseUrl: string;
    serviceName: string;
}

export default (ExtractValue: ExtractValueFn) => {
    return new Config<MyServiceClientConfig>({
        baseUrl: ExtractValue({
            name: 'baseUrl',
            value: 'http://endpoint',
        }).string,
    });
}
// lib/myServiceClient/index.ts
export default new ServiceClient('requesting-service', 'receiving-service', config.server.serviceName);

Publishing

Publish by running npm publish --access=restricted