# Custom Delay in API Responses

In API development and testing, it's often essential to simulate various network conditions, including response delays. This can help you assess how your application handles slow responses and timeouts. To achieve this, you can use the mock_delay query parameter in the API URL to introduce a custom delay in milliseconds to the API response.

# Syntax

To introduce a custom delay in the API response, follow this syntax:

https://mockanapi.com/s/endpoint?mock_delay=<custom_delay_in_ms>

  • mock_delay: This is the query parameter used to specify the custom delay.
  • <custom_delay_in_ms>: Replace this with the delay time you want in milliseconds, with a maximum allowed delay time of 30 seconds or 30000 milliseconds.

# Example

Suppose you have an API endpoint for fetching user data:

https://mockanapi.com/s/users/123

To simulate a custom delay of 5 seconds (5000 milliseconds) for this API call, you can modify the URL as follows:

https://mockanapi.com/s/users/123?mock_delay=5000

When you make a request to this modified URL, the API will introduce a 5-second delay before responding. This can be valuable for testing how your application handles slow API responses and timeouts.

# Maximum Allowed Delay

It's important to note that there is a maximum allowed delay of 30 seconds (30000 milliseconds) when using the mock_delay query parameter. Attempting to set a delay greater than this limit will result in the API still responding after the maximum allowed time has passed.

# Use Cases

The mock_delay query parameter can be beneficial in various scenarios:

  • Testing Timeout Handling: Evaluate how your application handles slow API responses and timeouts.
  • Simulating Network Latency: Mimic network latency to assess the performance of your application under varying network conditions.
  • Load Testing: Test how your application handles concurrent requests with different response delay times.