Skip to content

Commit

Permalink
Update Upgrade Guide
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jun 5, 2024
1 parent a8d3050 commit d80d993
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,32 @@ server.init(data);
+ { id: 3, title: 'boz' },
+ ],
+});
```

## Request and Response Interceptors Have Been Replaced By Middlewares

Fakerest used to have request and response interceptors. We replaced those with middlewares that allows much more use cases.

Migrate your request interceptors:

```diff
-restServer.addRequestInterceptor(function(request) {
+restServer.addMiddleware(async function(request, context, next) {
var start = (request.params._start - 1) || 0;
var end = request.params._end !== undefined ? (request.params._end - 1) : 19;
request.params.range = [start, end];
- return request; // always return the modified input
+ return next(request, context);
});
```

Migrate your response interceptors:

```diff
-restServer.addResponseInterceptor(function(response) {
+restServer.addMiddleware(async function(request, context, next) {
+ const response = await next(request, context);
response.body = { data: response.body, status: response.status };
return response;
});
```

0 comments on commit d80d993

Please sign in to comment.