@odg/message
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

Stanley Imagem
ODG Request Message Interface

Request Message Interface 🔗!

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

Readme

Keywords

none

Package Sidebar

Install

npm i @odg/message

Weekly Downloads

79

Version

1.3.1

License

MIT

Unpacked Size

49.5 kB

Total Files

27

Last publish

Collaborators

  • dragonsgamers