Skip to content

Commit 0ca876b

Browse files
committed
Adds interceptors comparison to the documentation
1 parent 230cc47 commit 0ca876b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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

76
Simple [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

4847
A 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.

docs/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ There are two classes exposed in this module:
1111

1212
It 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

1628
All 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

0 commit comments

Comments
 (0)