1.3.1 โข Published 10 months ago
@odg/message v1.3.1
Table of Contents
๐ Benefits
- ๐ Inversion of control (IoC)
- ๐ Dependency Injection (DI)
- ๐จ Over 800 rules for pattern, possible errors and errors in Linter
๐ Libraries
๐ Dependencies
- Node.js 16 or later
- Yarn Optional/Recommended
- ODG TsConfig Last Version
- ODG Exception Last Version
โฉ 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