File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 11# axios-middleware
22
33[ ![ Build Status] ( https://travis-ci.org/emileber/axios-middleware.svg?branch=master )] ( https://travis-ci.org/emileber/axios-middleware )
4- [ ![ Dependency Status] ( https://beta.gemnasium.com/badges/github.com/emileber/axios-middleware.svg )] ( https://beta.gemnasium.com/projects/github.com/emileber/axios-middleware )
54[ ![ npm version] ( https://badge.fury.io/js/axios-middleware.svg )] ( https://www.npmjs.com/package/axios-middleware )
65
76Simple [ axios] ( https://github.com/axios/axios ) HTTP middleware service.
@@ -42,7 +41,7 @@ service.register({
4241});
4342
4443// We're good to go!
45- export default { service } ;
44+ export default service ;
4645```
4746
4847A common use-case would be to expose an instance of the service which consumes an _ axios_ instance configured for an API. It's then possible to register middlewares for this API at different stages of the initialization process of an application.
Original file line number Diff line number Diff line change @@ -11,6 +11,18 @@ There are two classes exposed in this module:
1111
1212It works with either the global axios or a local instance.
1313
14+ ## Why not use interceptors?
15+
16+ Using axios interceptors makes the code tightly coupled to axios and harder to test.
17+
18+ This middleware service module:
19+
20+ - offers more functionalities (e.g. see [ ` onSync ` ] ( api/HttpMiddleware?id=onsyncpromise ) )
21+ - looser coupling to axios
22+ - really easy to test middleware classes
23+
24+ It improves readability and reusability.
25+
1426## Examples
1527
1628All examples are written using ES6 syntax but you can definitely use this plugin with ES5 code, even directly in the browser.
@@ -45,6 +57,6 @@ service.register({
4557});
4658
4759// We're good to go!
48- export default { service } ;
60+ export default service ;
4961```
5062
You can’t perform that action at this time.
0 commit comments