From d80d993cbda2009bf736bbeb243de1931b604d8d Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:54:44 +0200 Subject: [PATCH] Update Upgrade Guide --- UPGRADE.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 36af71b..aa2f745 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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; +}); ``` \ No newline at end of file