# Custom Status Code in API URL

Sometimes, during API development or testing, you may want to simulate specific HTTP status codes for various scenarios. To achieve this, you can append a query parameter mock_status to the API URL with your desired custom status code. This allows you to mimic different server responses for testing purposes.

# Syntax

To set a custom status code in the API response, follow this syntax:


  • mock_status: This is the query parameter used to specify the custom status code.
  • <custom_status_code>: Replace this with the HTTP status code you want to simulate, such as 200 for success, 404 for not found, 500 for server error, etc.

# Example

Let's say you have an API endpoint for user data:


To simulate a 404 Not Found response for user ID 123, you can modify the URL as follows:


When you make a request to this modified URL, the API will respond with an HTTP status code of 404, indicating that the requested resource was not found.

# Use Cases

Using the mock_status query parameter can be helpful in various scenarios:

  • Testing Error Handling: You can test how your application handles different HTTP error responses.
  • Simulating Server Issues: Simulate server errors (e.g., 500 Internal Server Error) to test error-handling mechanisms.
  • Verifying Redirects: Ensure that your application handles redirections (e.g., 301 Moved Permanently, 302 Found) correctly.