1.3.1 โ€ข Published 10 months ago

@odg/message v1.3.1

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

codecov Stargazers Made by ODGodinho Forks Repository size GitHub last commit License StyleCI

Table of Contents


๐ŸŽ‡ Benefits

  • ๐Ÿ‘€ Inversion of control (IoC)
  • ๐ŸŽ‡ Dependency Injection (DI)
  • ๐Ÿšจ Over 800 rules for pattern, possible errors and errors in Linter

๐Ÿ“— Libraries

๐Ÿ“ Dependencies

โฉ Get Started


๐Ÿ”˜ Add dependencies

yarn add @odg/message

๐Ÿ’ป Usage

for use axios implementation click here

class Test {

    public constructor(private readonly requester: MessageInterface) {
    }

    public async example(): ResponseInterface<any, any> {
        return this.requester.request({
            url: "https://google.com",
        });
    }

}

๐Ÿ“ฐ Example Implements

import axios, {
    type AxiosInstance,
    type AxiosResponse,
    type AxiosResponseHeaders,
} from "axios";

import {
    type HttpHeadersInterface,
    type InterceptorManager,
    type RequestInterface ,
    type MessageInterface,
    type ResponseInterface,
    MessageException,
} from "@odg/message";

export class AxiosMessage<RequestData, ResponseData> implements MessageInterface<RequestData, ResponseData> {

    public interceptors: {
        request: InterceptorManager<RequestInterface<RequestData>>;
        response: InterceptorManager<ResponseInterface<RequestData, ResponseData>>;
    };

    private readonly client: AxiosInstance;

    public constructor() {
        this.client = axios.create();
        // this.interceptors = implements;
    }

    public async request<
        RequestD = RequestData,
        ResponseD = ResponseData,
    >(config: RequestInterface<RequestD>): Promise<ResponseInterface<RequestD, ResponseD>> {
        try {
            const response = await this.client.request<ResponseD, AxiosResponse<ResponseD, RequestD>, RequestD>(config);

            return {
                data: response.data,
                status: response.status,
                headers: response.headers,
                request: response.config,
            };
        } catch (error: unknown) {
            throw new MessageException("Example");
        }
    }
}

๐Ÿงช Teste Code

To Test execute this command

yarn test
# or
yarn test:watch
1.3.1

10 months ago

1.3.0

10 months ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.0.0

2 years ago