Mock fail api https://github.com/datmt/failapi4j
198
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}
timeoutMs: Delay duration in millisecondsExample:
# Simulate 2-second timeout
curl http://localhost:8080/api/timeout/2000
Endpoint: /api/error/{statusCode}
statusCode: HTTP status code to return (e.g., 400, 404, 500)Example:
# Simulate 404 Not Found error
curl http://localhost:8080/api/error/404
Endpoint: /api/random/{errorPercent}/{delayMs}/{statusCode}
errorPercent: Probability of error (0-100)delayMs: Delay in millisecondsstatusCode: HTTP status code for error responses{"content": "success"}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:
git clone https://github.com/yourusername/failapi4j.git
cd failapi4j
mvn clean install
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:
Contributions are welcome! Please feel free to submit a Pull Request.
Content type
Image
Digest
sha256:91c99a645…
Size
145.7 MB
Last updated
over 1 year ago
docker pull dattm24/failapi4j