prism icon indicating copy to clipboard operation
prism copied to clipboard

API Response Delay

Open mswolfe opened this issue 5 years ago • 14 comments

User story. As an Engineer, I would like to specify a global response delay, so that I can more accurately model response timings of downstream APIs.

Is your feature request related to a problem? I work with a lot of older internal systems that are not the most performant. They can yield response times in seconds and I would like to be able to reflect this in the prism mock we run as well. It will help us validate our client code can handle these longer response times correctly and would be a great help.

Describe the solution you'd like I would like to be able to configure a global response delay for all requests that I send to the mock either via the command line or from within the OpenAPI document itself.

Additional context N/A

mswolfe avatar Apr 28 '20 18:04 mswolfe

I like the sound of this. We're trying to keep stuff out of the OpenAPI document as much as possible, but due to the global nature this one might actually make sense.

A CLI too ofc.

@XVincentX what do you think?

philsturgeon avatar Apr 29 '20 10:04 philsturgeon

We did something similar for callbacks btw, we could try to name and implement things as consistently as possible with https://github.com/stoplightio/prism/issues/775

philsturgeon avatar Apr 29 '20 10:04 philsturgeon

This would be very useful indeed!

cor3ntin avatar Aug 17 '20 08:08 cor3ntin

Yes, we'd be interested in this too.

tommaisey avatar Aug 17 '20 08:08 tommaisey

+1

CLI option preferred, don't think it belongs in the specification document.

skrivanos avatar Aug 18 '20 21:08 skrivanos

We might want to make that happen, yeah.

XVincentX avatar Aug 19 '20 06:08 XVincentX

+1 as a CLI option, this would be mega useful for us!

bdavies avatar Oct 28 '20 15:10 bdavies

@bdavies is there any chance you could take a stab at implementing this? These are open source tools but we still write 99% of the code, and there’s a lot of functionality people want. Help would be massively appreciated and we reward folks with tree donations in their name!

philsturgeon avatar Oct 28 '20 15:10 philsturgeon

+1 Instead of a CLI option why not adding delay as an http config header? I think it brings more flexibility, since we could set delay for each request.

skyanceschia avatar Jul 21 '21 14:07 skyanceschia

Why not both? In our use case we auto-generate the API calls and it is easier/more convenient to us using the CLI option. For sure there are use cases where the http header is preferred.

enekonieto avatar Jul 22 '21 08:07 enekonieto

One approach we're considering here is to include an example in the Prism documentation that shows how to set up and use a proxy specifically to introduce latency and/or low bandwidth into the request-response cycle. Would that satisfy your needs?

EdVinyard avatar Mar 18 '22 16:03 EdVinyard

One approach we're considering here is to include an example in the Prism documentation that shows how to set up and use a proxy specifically to introduce latency and/or low bandwidth into the request-response cycle. Would that satisfy your needs?

It would be very useful!

skyanceschia avatar Mar 18 '22 16:03 skyanceschia

Can I take this up?

I recently needed the same feature for a work-related project, and I already have a forked version of this code with the above feature implemented.

This is the commit for the same: https://github.com/sarkarshuvojit/prism/commit/809f619376c4f080ebbd23f13d370cf091092b0c

sarkarshuvojit avatar Apr 17 '22 18:04 sarkarshuvojit

@sarkarshuvojit , we appreciate your offer!

However, because there are some fantastic and very flexible tools for these purposes already (e.g., Toxiproxy), our intent is to document how to include any proxy in front of Prism, rather than introduce a new feature-set in Prism itself. We'll do that in https://github.com/stoplightio/prism/issues/2032 and close this issue with that one.

EdVinyard avatar Apr 18 '22 16:04 EdVinyard

hello, I am in need now for a delay of the responses from prism. Is there a way to do this?

bogi158 avatar May 03 '23 13:05 bogi158

@bogi158 , we recommend using a separate tool. I think there are modules available for some HTTP servers (e.g., NGINX), and stand-alone proxies (e.g., toxiproxy, delay-proxy) that do what you're suggesting. You may find our example of adding a proxy for additional example-selection logic helpful.

EdVinyard avatar May 03 '23 14:05 EdVinyard