Back to Blog
January 5, 20267 min readHow to make

How to make video capture from UIs: Create an API from videos using the platform

R
Replay Team
Developer Advocates

TL;DR: Learn how to create a functional API endpoint directly from video recordings of user interface interactions using Replay's behavior-driven reconstruction engine.

Turning UI Videos into Functional APIs: A Developer's Guide#

The dream of automatically generating code from visual input has been around for a while. Screenshot-to-code tools offer a glimpse, but they often fall short when dealing with dynamic user interactions and multi-page flows. What if you could take a video of a user interacting with your UI and instantly generate a working API endpoint that captures that behavior? That's the power of behavior-driven reconstruction.

Replay takes a unique approach by analyzing video recordings of UI interactions to generate functional code. It doesn't just see pixels; it understands user intent. This opens up possibilities for rapid prototyping, automated testing, and reverse engineering existing systems.

The Problem with Traditional Screenshot-to-Code#

Screenshot-to-code tools are limited by their static nature. They can generate UI components based on a single image, but they struggle to capture the dynamic behavior of a user interacting with the interface. Consider a scenario where a user fills out a form, clicks a button, and navigates to a new page. A screenshot-to-code tool would only capture the initial state of the form, missing the crucial interactions and the subsequent data flow.

Behavior-Driven Reconstruction: Video as the Source of Truth#

Replay solves this problem by using video as the source of truth. By analyzing the video, Replay can understand the sequence of user actions, the data entered into forms, and the resulting state changes. This allows it to generate code that accurately reflects the user's behavior, including API calls, data transformations, and navigation logic.

FeatureScreenshot-to-CodeReplay
Input TypeStatic ImagesVideo Recordings
Behavior AnalysisLimitedComprehensive
Multi-Page SupportPoorExcellent
API GenerationBasicAdvanced, including data extraction and request construction
Understanding User IntentLowHigh

Building an API from a UI Video: A Step-by-Step Guide#

Let's walk through the process of creating an API endpoint from a video using Replay. We'll use a simple example of a user submitting a contact form on a website.

Step 1: Capture the UI Interaction#

Record a video of a user filling out the contact form. Make sure the video clearly shows all the user's actions, including typing in the form fields, clicking the submit button, and any subsequent page navigation or feedback messages.

💡 Pro Tip: Ensure the video quality is good and the UI elements are clearly visible for optimal analysis by Replay.

Step 2: Upload and Analyze the Video in Replay#

Upload the video to Replay. The platform will automatically analyze the video, identifying UI elements, user interactions, and data flow. This process leverages Gemini's powerful video understanding capabilities to reconstruct the underlying logic of the application.

Step 3: Review and Refine the Reconstructed Code#

Replay generates code based on its analysis of the video. This code might include:

  • UI components (HTML, CSS, JavaScript)
  • API request definitions (endpoints, methods, parameters)
  • Data extraction logic (parsing form data)
  • Event handlers (button clicks, form submissions)

Review the generated code and make any necessary refinements. Replay provides a user-friendly interface for editing and customizing the code to meet your specific requirements.

Step 4: Define the API Endpoint#

Replay allows you to define the API endpoint that will handle the form submission. You can specify the URL, HTTP method (e.g., POST), and any necessary authentication or authorization headers.

typescript
// Example API endpoint definition in Replay { url: '/api/contact', method: 'POST', headers: { 'Content-Type': 'application/json' }, body: { name: '{{name}}', // Extracted from the video email: '{{email}}', // Extracted from the video message: '{{message}}' // Extracted from the video } }

📝 Note: The

text
{{name}}
,
text
{{email}}
, and
text
{{message}}
placeholders are automatically populated by Replay based on the data entered in the video.

Step 5: Implement the API Logic (Backend)#

While Replay reconstructs the API definition from the video, you still need to implement the actual API logic on your backend. This might involve saving the form data to a database, sending an email notification, or integrating with other services.

Here's an example of how you might implement the API endpoint using Node.js and Express:

javascript
const express = require('express'); const app = express(); const port = 3000; app.use(express.json()); // for parsing application/json app.post('/api/contact', (req, res) => { const { name, email, message } = req.body; // TODO: Save the data to a database or send an email console.log(`Received contact form submission: Name=${name}, Email=${email}, Message=${message}`); res.status(200).send('Thank you for your submission!'); }); app.listen(port, () => { console.log(`Server listening at http://localhost:${port}`); });

⚠️ Warning: Remember to sanitize and validate the input data to prevent security vulnerabilities such as SQL injection or cross-site scripting (XSS).

Step 6: Test the API Endpoint#

Test the API endpoint by sending a sample request with valid data. Verify that the data is correctly processed on the backend and that the expected response is returned.

You can use tools like Postman or

text
curl
to send test requests:

bash
curl -X POST -H "Content-Type: application/json" -d '{"name": "John Doe", "email": "john.doe@example.com", "message": "This is a test message."}' http://localhost:3000/api/contact

Replay Features that Enhance API Creation#

Replay offers several features that make the process of creating APIs from UI videos even easier:

  • Multi-page generation: Replay can handle complex user flows that span multiple pages, automatically generating the necessary API calls and data transformations.
  • Supabase integration: Replay seamlessly integrates with Supabase, allowing you to quickly store and retrieve data from your database.
  • Style injection: Replay can extract CSS styles from the video and apply them to the generated UI components, ensuring a consistent look and feel.
  • Product Flow maps: Replay creates visual diagrams of the user flow, making it easier to understand the interactions and identify potential areas for optimization.

Real-World Use Cases#

The ability to create APIs from UI videos has a wide range of potential applications:

  • Rapid Prototyping: Quickly generate API endpoints for new features by recording a simple UI interaction.
  • Automated Testing: Create automated tests that simulate user behavior by replaying the video and verifying the API responses.
  • Reverse Engineering: Understand the functionality of existing systems by analyzing videos of user interactions and generating the corresponding API definitions.
  • Documentation: Generate API documentation automatically from video recordings of user interactions.

Frequently Asked Questions#

Is Replay free to use?#

Replay offers a free tier with limited features. Paid plans are available for users who need more advanced functionality or higher usage limits. Check the Replay pricing page for the latest details.

How is Replay different from v0.dev?#

While both tools aim to generate code automatically, Replay focuses on behavior-driven reconstruction from video, understanding user intent and generating functional APIs. v0.dev primarily uses text prompts and AI to generate UI components, lacking the ability to analyze and reconstruct behavior from video recordings. Replay excels at capturing dynamic interactions and multi-page flows, a significant advantage over screenshot-to-code or prompt-based tools.


Ready to try behavior-driven code generation? Get started with Replay - transform any video into working code in seconds.

Ready to try Replay?

Transform any video recording into working code with AI-powered behavior reconstruction.

Launch Replay Free