@odata2ts/http-client-base
v0.5.3
Published
Core functionality for odata2ts HTTP clients
Downloads
16,408
Maintainers
Readme
OData HTTP Client Base
Base implementation for odata2ts compatible HTTP clients:
- implements automatic CSRF token handling
- allows user to set custom CSRF token header key (default:
x-csrf-token
)
- allows user to set custom CSRF token header key (default:
- implements standard error message retrieval method for OData error responses
- works for V2 & V4
- allows user to set custom retrieval method
- streamlines all HTTP calls (POST, GET, ...) into one method
Installation
Install package @odata2ts/http-client-base
as dependency:
npm install --save @odata2ts/http-client-base
Usage
Extend the class BaseHttpClient
to simplify your HttpClient implementation.
You need to implement two abstract methods:
import { BaseHttpClient, BaseHttpClientOptions, InternalHttpClientConfig } from "@odata2ts/http-client-base";
export interface MyRequestConfig {}
export class MyHttpClient extends BaseHttpClient<MyRequestConfig> {
constructor(clientOptions: BaseHttpClientOptions) {
super(clientOptions);
}
protected async executeRequest<ResponseModel>(
method: HttpMethods,
url: string,
data: any,
requestConfig: AxiosRequestConfig | undefined = {},
internalConfig?: InternalHttpClientConfig,
): Promise<HttpResponseModel<ResponseModel>> {
// your implementation
}
}
Compare any of the existing clients.
Documentation
Main documentation for the odata2ts eco system: https://odata2ts.github.io
Tests
See folder test for unit tests.
Support, Feedback, Contributing
This project is open to feature requests, suggestions, bug reports, usage questions etc. via GitHub issues.
Contributions and feedback are encouraged and always welcome.
See the contribution guidelines for further information.
License
MIT - see License.