Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there anyway to delay the response time? #647

Open
toe-lai opened this issue Oct 6, 2017 · 7 comments
Open

Is there anyway to delay the response time? #647

toe-lai opened this issue Oct 6, 2017 · 7 comments

Comments

@toe-lai
Copy link

toe-lai commented Oct 6, 2017

I would like to delay the response time about 30s for testing loading case. Is it possible?

@toe-lai toe-lai changed the title Is there anyway to delay the response? Is there anyway to delay the response time? Oct 6, 2017
@djhojd
Copy link

djhojd commented Oct 7, 2017

Check CLI usage, you can add --delay [ms], in your case either start with json-server --delay 30000 or create a file called json-server.json and add that option there.

@159159951
Copy link

Hi @toe-lai,
Your question is resolved before in this link:
#188

@Aliyamash
Copy link

how can i add it in json-server.json ?

@Rockheung
Copy link

Please give us back --delay option.

@piotr-jura-udemy
Copy link

Not sure why delay was removed. "use Chrome's Network tab > throttling to delay requests instead of --delay CLI option". What if I used json-server in Next 14 app dir, where I fetch data on the server? How I'm supposed to enable throttling there?

@typicode
Copy link
Owner

typicode commented Feb 1, 2024

You can do it like this:

const sleep = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));

await sleep(5000)
await fetch(...)

And if you're using something like axios, probably with an interceptor. There's more control over which request should have a delay or not.

On macOS, you have Network Link Conditioner as well.

@nashashibi
Copy link

i've raised this PR.

meanwhile, I made the same changes locally in the globally installed package and is working fine.

You can check the PR and do the same if you don't wanna wait 🤓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants