- 👀 Inversion of control (IoC)
- 🎇 Dependency Injection (DI)
- 🚨 Over 800 rules for pattern, possible errors and errors in Linter
- Node.js 16 or later
- Yarn Optional/Recommended
- ODG TsConfig Last Version
- ODG Exception Last Version
yarn add @odg/message
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",
});
}
}
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");
}
}
}
To Test execute this command
yarn test
# or
yarn test:watch