On 4/11/17, 9:44 PM, "omup...@gmail.com on behalf of OmPrakash Muppirala"
<omup...@gmail.com on behalf of bigosma...@gmail.com> wrote:
>
>One common approach I have seen in JS webservice libraries is to allow the
>users to attach an interceptor function which will carry the requrst
>object
>in the function args.  The user can then attach any headers they want to
>the request object inside the function.
>
>This would be a static method on HTTPService.  That way, for example, once
>authenticated, all api calls could be intercepted and authentication
>headers attached.  Or perhaps CORS headers attached if the situation
>requires.
>
>In runtime we check
>
>if(HttpService.interceptor) {
>    HTTPService. interceptor.call(this.request);
>}

If I understand that pattern, it and other callback patterns are ok, but
not my favorite pattern because it sort of implies that there is only one
interceptor.  That's what I like about events and other multi-subscriber
patterns:  any number of other objects can find out what is going on and
remove themselves from the list of folks that care.

My 2 cents,
-Alex

Reply via email to