From fa085ac4e8438c03dd15f9bae350bd9fb3279c79 Mon Sep 17 00:00:00 2001 From: nutboltu Date: Sun, 28 Nov 2021 11:15:49 +1100 Subject: [PATCH] chore: update README.md --- README.md | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d55f9d0..b164282 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ There are few packages those help the developers to mock the backend requests wh | Property | Description | Required | Default | | ---------- | :------------------------------------------------------------------------------------------ | :------- | :------ | -| `url` | Supports both **named parameters** (`/:foo/:bar`) and **query parameters**(`/foo?bar=true`) | Y | - | -| `method` | Supports `GET`, `POST`, `PUT`, `PATCH` and `DELETE` methods | - | `GET` | -| `status` | All possible HTTP status codes | - | `200` | -| `response` | JSON format or function `({ url: string, method: string, body: string \| null }) => JSON` | Y | - | -| `delay` | Emulate delayed response time in milliseconds | - | `0` | +| `url` | Supports both **named parameters** (`/:foo/:bar`) and **query parameters**.(`/foo?bar=true`) | Y | - | +| `method` | Supports `GET`, `POST`, `PUT`, `PATCH` and `DELETE` methods. | - | `GET` | +| `status` | All possible HTTP status codes. | - | `200` | +| `response` | JSON format or function.

Response function is a function that contains request object as a parameter. See the **Custom Response** section for example. | Y | - | +| `delay` | Emulate delayed response time in milliseconds. | - | `0` | > You can change the **status**, **response** and **delay** from the storybook panel on the fly! :rocket: @@ -131,10 +131,26 @@ Default.parameters = { url: 'https://jsonplaceholder.typicode.com/todos/1', method: 'GET', status: 200, - response: (req) => { + response: (request) => { + const { + url, + method, + body, + searchParams, + } = request; + + if (searchParams.id == 1) { + return { + data: 'Custom data for id 1', + }; + } else if (body.name === 'mock') { + return { + data: 'Custom data for name mock', + } + } return { - data: `Hello ${JSON.parse(req).name}`, - }; + data: 'Default data', + } }, }, ],