Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ODataService Ajax request interceptor #61

Closed
buchatsky opened this issue May 27, 2022 · 0 comments
Closed

ODataService Ajax request interceptor #61

buchatsky opened this issue May 27, 2022 · 0 comments

Comments

@buchatsky
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant