prism
prism copied to clipboard
API Response Delay
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
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?
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
This would be very useful indeed!
Yes, we'd be interested in this too.
+1
CLI option preferred, don't think it belongs in the specification document.
We might want to make that happen, yeah.
+1 as a CLI option, this would be mega useful for us!
@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!
+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.
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.
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?
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!
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 , 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.
hello, I am in need now for a delay of the responses from prism. Is there a way to do this?
@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.