A Spring Boot API designed to simulate various API failure scenarios for testing and development purposes. This tool helps developers test how their applications handle different types of API failures, including timeouts, specific HTTP errors, and random failures with configurable probabilities.
Endpoint: /api/timeout/{timeoutMs}
- Simulates API timeouts with specified delay
- Supports all HTTP methods (GET, POST, PUT, DELETE, PATCH)
- Parameter:
timeoutMs
: Delay duration in milliseconds
Example:
# Simulate 2-second timeout
curl http://localhost:8080/api/timeout/2000
Endpoint: /api/error/{statusCode}
- Returns specified HTTP error responses
- Supports all HTTP methods
- Parameter:
statusCode
: HTTP status code to return (e.g., 400, 404, 500)
- Returns JSON with status, error message, and timestamp
Example:
# Simulate 404 Not Found error
curl http://localhost:8080/api/error/404
Endpoint: /api/random/{errorPercent}/{delayMs}/{statusCode}
- Simulates errors with configurable probability and delay
- Supports all HTTP methods
- Parameters:
errorPercent
: Probability of error (0-100)delayMs
: Delay in millisecondsstatusCode
: HTTP status code for error responses
- Success Response:
{"content": "success"}
- Error Response: JSON with status, error message, and timestamp
Example:
# 50% chance of 404 error with 1-second delay
curl http://localhost:8080/api/random/50/1000/404
The API is documented using OpenAPI (Swagger). You can access the interactive API documentation at:
http://localhost:8080/swagger-ui.html
This provides:
- Interactive API documentation
- Request/response examples
- Try-it-out functionality
- Detailed parameter descriptions
- Response schemas
- Java 21
- Spring Boot 3.4.3
- Maven
- Clone the repository:
git clone https://github.com/yourusername/failapi4j.git
cd failapi4j
- Build the project:
mvn clean install
- Run the application:
mvn spring-boot:run
The application will start on http://localhost:8080
.
docker build -t failapi4j .
docker run -d -p 8080:8080 --name failapi4j failapi4j
JAVA_OPTS
: JVM options (default: "-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0")
Example with custom Java options:
docker run -d -p 8080:8080 -e JAVA_OPTS="-Xmx512m" --name failapi4j failapi4j
The API supports all standard HTTP status codes. Here are some commonly used ones:
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 408: Request Timeout
- 429: Too Many Requests
- 500: Internal Server Error
- 503: Service Unavailable
- 504: Gateway Timeout
- Testing error handling in client applications
- Simulating unreliable network conditions
- Load testing with variable response times
- Testing retry mechanisms
- Validating error handling UI/UX
- Testing circuit breakers and fallback mechanisms
Contributions are welcome! Please feel free to submit a Pull Request.