@odg/message
v1.3.1
Published
Interface request fo inversion of control
Downloads
350
Readme
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