You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.then(({ data }) =>console.log('Received:', data));
61
+
```
62
+
63
+
It should output:
64
+
65
+
```
66
+
Ready to fetch.
67
+
onRequest
68
+
onSync
69
+
onResponse
70
+
Received: {userId: 1, id: 1, title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", body: "quia et suscipit↵suscipit recusandae consequuntur …strum rerum est autem sunt rem eveniet architecto"}
Copy file name to clipboardExpand all lines: docs/api/Service.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# HttpMiddlewareService
1
+
# Middleware `Service` class
2
2
3
-
This is the heart of this plugin module. It works by leveraging axios' adapter to call its middleware stack at each relevant steps of a request.
3
+
This is the heart of this plugin module. It works by leveraging axios' adapter to call its middleware stack at each relevant steps of a request lifecycle.
4
4
5
5
## `constructor(axios)`
6
6
@@ -26,7 +26,7 @@ Returns `true` if the passed `middleware` instance is within the stack.
26
26
27
27
Adds a middleware instance or an array of middlewares to the stack.
28
28
29
-
You can pass an `HttpMiddleware` instance or a simple object implementing only the functions you need (see the [simplified syntax](simplified-syntax.md)).
29
+
You can pass a class instance or a simple object implementing only the functions you need (see the [simplified syntax](simplified-syntax.md)).
30
30
31
31
!> Throws an error if a middleware instance is already within the stack.
Copy file name to clipboardExpand all lines: docs/api/methods.md
+4-8Lines changed: 4 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,8 @@
1
-
# HttpMiddleware
1
+
# The middleware methods
2
2
3
-
?> This class is optional if you opt to use the [simplified syntax](simplified-syntax.md).
3
+
These will be called at different step of a request lifecycle. Each method can return a promise which will be resolved or reject before continuing through the middleware stack.
4
4
5
-
The base implementation to inherit when creating your custom implementation. **Any function is optional** and should be provided within a custom middleware only if needed.
6
-
7
-
## `constructor`
8
-
9
-
The constructor isn't used in the default middleware, leaving it totally available to the child classes. Very useful to pass any relevant services your middleware might need, like [the `i18n` service in our example](examples/locale-middleware.md).
5
+
?> **Any function is optional** and should be provided within a custom middleware only if needed.
10
6
11
7
## `onRequest(config)`
12
8
@@ -36,7 +32,7 @@ onResponse(response) {
36
32
}
37
33
```
38
34
39
-
!> The original `response` object, _a new one_, or a promise should be returned.
35
+
!> The original `response` object, or _a new/modified one_, or a promise should be returned.
Copy file name to clipboardExpand all lines: docs/examples/es5.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
# Usage with ES5 in Node
2
2
3
-
ES5 doesn't have [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) so you can't use the easy extend syntax sugar. Creating a new middleware from the base `HttpMiddleware` class can still be done with a typical prototype based inheritance pattern.
3
+
ES5 doesn't have [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) so you can't use the easy extend syntax sugar. Creating a new middleware from a base middleware class can still be done with a typical prototype based inheritance pattern.
Copy file name to clipboardExpand all lines: docs/simplified-syntax.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Simplified syntax for middlewares
2
2
3
-
Instead of creating a class from the [`HttpMiddleware`](api/HttpMiddleware.md) base class, you can use a simple object literal only implementing the functions you need.
3
+
Instead of creating a class, you can use a simple object literal only implementing the [methods](api/methods.md) you need.
0 commit comments