{"action":"created","issue":{"url":"https://api.github.com/repos/SpoonX/aurelia-api/issues/178","repository_url":"https://api.github.com/repos/SpoonX/aurelia-api","labels_url":"https://api.github.com/repos/SpoonX/aurelia-api/issues/178/labels{/name}","comments_url":"https://api.github.com/repos/SpoonX/aurelia-api/issues/178/comments","events_url":"https://api.github.com/repos/SpoonX/aurelia-api/issues/178/events","html_url":"https://github.com/SpoonX/aurelia-api/issues/178","id":185628429,"number":178,"title":"Better implementation of Interceptors","user":{"login":"TomFoyster","id":10615058,"avatar_url":"https://avatars.githubusercontent.com/u/10615058?v=3","gravatar_id":"","url":"https://api.github.com/users/TomFoyster","html_url":"https://github.com/TomFoyster","followers_url":"https://api.github.com/users/TomFoyster/followers","following_url":"https://api.github.com/users/TomFoyster/following{/other_user}","gists_url":"https://api.github.com/users/TomFoyster/gists{/gist_id}","starred_url":"https://api.github.com/users/TomFoyster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomFoyster/subscriptions","organizations_url":"https://api.github.com/users/TomFoyster/orgs","repos_url":"https://api.github.com/users/TomFoyster/repos","events_url":"https://api.github.com/users/TomFoyster/events{/privacy}","received_events_url":"https://api.github.com/users/TomFoyster/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-27T10:18:42Z","updated_at":"2016-10-27T12:27:46Z","closed_at":null,"body":"Having worked with Aurelia-API for a couple of months now, I'm finding dealing with the interceptors very restrictive. I know too that others have had issue with these, recently @rafaelcamargo has ran in to the same troubles as I. \r\n\r\nI understand that the interceptors used through Aurelia-API are actually just the interceptors originating in the Aurelia Fetch Client. However, as Aurelia-API is a wrapper for the Fetch Client, I feel that it should offer a better implementation of the interceptors. \r\n\r\nThere is a couple of main issues;\r\n\r\nThe Response Interceptor doesn't allow access to the response body. The response body at the point the interceptor runs is a _ReadableStream_. This can be read by introducing an async promise to parse the JSON once the body has been recieved, but introducing this promise into the repsonse flow breaks the process. In my opinion - there should be a method available to intercept the response when it has completed, and before the result it passed back to the calling method. \r\n\r\nIn a similar vein the request interceptor - it seems - offers no way of actually altering the request or its headers prior to the request being made. I had a use case where I needed to take a version from the request body (which was JSON) and add it to the If-Match header. As I couldn't do this through the interceptor I had to create my own wrapper, which wraps Aurelia-API, to set the headers prior to the request being made, and then unsets them afterwards. It really wasn't an ideal solution. \r\n\r\nI'd love to hear your thoughts on whether Aurelia-API can offer better, and actually useful, Interceptors."},"comment":{"url":"https://api.github.com/repos/SpoonX/aurelia-api/issues/comments/256626972","html_url":"https://github.com/SpoonX/aurelia-api/issues/178#issuecomment-256626972","issue_url":"https://api.github.com/repos/SpoonX/aurelia-api/issues/178","id":256626972,"user":{"login":"doktordirk","id":13430091,"avatar_url":"https://avatars.githubusercontent.com/u/13430091?v=3","gravatar_id":"","url":"https://api.github.com/users/doktordirk","html_url":"https://github.com/doktordirk","followers_url":"https://api.github.com/users/doktordirk/followers","following_url":"https://api.github.com/users/doktordirk/following{/other_user}","gists_url":"https://api.github.com/users/doktordirk/gists{/gist_id}","starred_url":"https://api.github.com/users/doktordirk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doktordirk/subscriptions","organizations_url":"https://api.github.com/users/doktordirk/orgs","repos_url":"https://api.github.com/users/doktordirk/repos","events_url":"https://api.github.com/users/doktordirk/events{/privacy}","received_events_url":"https://api.github.com/users/doktordirk/received_events","type":"User","site_admin":false},"created_at":"2016-10-27T12:27:46Z","updated_at":"2016-10-27T12:27:46Z","body":"background:\r\n* aurelia-fetch-client should have been immutable and transient (as they admitted)\r\n* that'll be kinda problem for aurelia-authentication since it adds interceptors\r\n* generally i was more thinking of easing the use of additional interceptors for authentication since that could cleanup  the mess with all those token response formats\r\n* as for working with the body: generally the rest! server should provide properly formatted responses. \r\n\r\ngiven that, one can currently add interceptors either later or with a configuration function. however, the former doesn't treat the client as immutable and the latter is a nuisance since configuration by object is much easier. hence, i see the need to allow referencing interceptors in the config object to aurelia-api\r\n\r\nas for working with the body. yeah, that's really more an aurelia-fetch-client issue. though it would make things easier if aurelia-api would not automatically call .json() on an already read stream. hence, i think we should add a check for that"}}
{"actor":{"display_login":"doktordirk"}}