Heygen Backend is a simulation of a video translation backend that allows you to configure delays and results for testing purposes. This backend is paired with a client library to implement intelligent polling and interact with the /status API efficiently.
- Simulates a video translation backend with configurable delay and result (
pending,completed,error). - Provides APIs for setting up test scenarios and fetching task statuses.
- Includes a client library with intelligent polling and exponential backoff mechanism.
- Logs detailed task execution steps and results for easy debugging.
- Java: JDK 11 or higher for backend logic.
- Spring Boot: To create RESTful APIs.
- Maven: For dependency management and build automation.
- HTML & CSS: For the test configuration page.
- Java Development Kit (JDK) 11 or higher
- Maven for dependency management
- Git for version control
-
Clone the repository:
git clone https://github.com/haoq4/heygen-backend.git cd heygen-backend -
Start the backend server:
mvn spring-boot:run
-
Open your browser and navigate to:
http://localhost:8080to access the instruction page.http://localhost:8080/statusto check the API status.http://localhost:8080/testto configure and test the backend.
To use the client library, add the VideoTranslationClient to your project and configure it as shown below:
import com.heygen.client.VideoTranslationClient;
public class ClientLibraryExample {
public static void main(String[] args) {
try {
// Initialize the client
VideoTranslationClient client = new VideoTranslationClient("http://localhost:8080", 10, 1000);
// Fetch the task status
String finalStatus = client.getStatus();
System.out.println("Final Task Status: " + finalStatus);
} catch (Exception e) {
System.err.println("An error occurred: " + e.getMessage());
}
}
}Fetches the current task status.
- Responses:
{"result": "pending"}{"result": "completed"}{"result": "error"}
Sets up the backend with custom parameters for testing.
- Request Parameters:
result: The desired final state (completedorerror).delay: The time in seconds before the task transitions to the final state.
Runs the integration test and returns detailed logs.
Starting integration test...
Request #1 at 2024-11-20T05:15:07.951 - Status: pending
Task is still pending, retrying... (Retry #1, Delay: 1000 ms)
Request #2 at 2024-11-20T05:16:10.015 - Status: pending
Request #3 at 2024-11-20T05:18:20.230 - Status: completed
Task completed successfully!
Integration Test Completed - Final Result: completed
heygen-backend/
├── src/
│ ├── main/
│ │ ├── java/com/heygen/ # Source code
│ │ │ ├── controllers/ # API Controllers
│ │ │ ├── client/ # Client Library
│ │ │ ├── model/ # Data Models
│ │ └── resources/
│ │ ├── static/ # Static resources (e.g., HTML)
│ │ └── application.properties
│ └── test/ # Test cases
├── pom.xml # Maven configuration
├── README.md # Project documentation
Here is a screenshot of the test page:
The test page allows users to configure the result and delay of the simulated video translation backend.
