jinqu-odata
jinqu-odata copied to clipboard
ODataService Ajax request interceptor
jinqu-odata version
1.1.3
Proposed behavior
ODataService Ajax request interceptor (e.g. for adding Authorization http header) as an option in ODataService initialization Implementation:
export interface IAjaxInterceptor {
intercept(options: AjaxOptions): AjaxOptions;
}
export interface IODataServiceOptions<TResponse> {
...
ajaxInterceptor?: IAjaxInterceptor;
}
...
if (this.options.ajaxInterceptor) {
o = this.options.ajaxInterceptor.intercept(o);
}
return this.options.ajaxProvider.ajax(o)
...
Usage:
const svc = new ODataService({
ajaxProvider: provider,
ajaxInterceptor: {
intercept: (options) => {
//options.headers = Object.assign({}, options.headers, { Authorization: "67890" } ); // copying is bad
if (!options.headers) options.headers = {};
options.headers['Authorization'] = "67890";
return options;
}
}
});
Actual behavior
There is no single point of interception for such task. The options currently available:
- adding .withOptions() to every dataset property/method in ODataService subclass
- using Web framework mechanisms (e.g. HttpInterceptor for Angular)
PS. Already done in my repository