3.5 KiB
3.5 KiB
ViewEngine Web Sample
A standalone web application that demonstrates how to use the ViewEngine REST API. Users can test page retrieval and see the results including content, thumbnails, and metadata.
Features
- 🔑 API Key Management - Securely stored in browser localStorage
- 🌐 URL Retrieval - Enter any URL to retrieve its content
- 📊 Real-time Status - Live polling shows retrieval progress
- 📸 Thumbnail Display - View captured page thumbnails
- 📄 Content Preview - See the full page data JSON
- 🎨 Modern UI - Beautiful, responsive interface
Getting Started
Prerequisites
- .NET 9.0 SDK
- A ViewEngine API key (get one from https://www.viewengine.io)
Running the Application
-
Navigate to the project directory:
cd ViewEngine.WebSample -
Run the application:
dotnet run -
Open your browser:
- Navigate to
http://localhost:5000orhttps://localhost:5001
- Navigate to
-
Enter your API key:
- Paste your ViewEngine API key in the API Key field
- The key is stored locally in your browser for convenience
-
Test a retrieval:
- Enter a URL (e.g.,
https://example.com) - Optionally check "Force fresh retrieval" to bypass cache
- Click "Retrieve Page"
- Watch the real-time progress as the page is processed
- View the results including thumbnail and content
- Enter a URL (e.g.,
How It Works
Architecture
Browser <-> WebSample Server <-> ViewEngine API
The WebSample server acts as a proxy to:
- Keep your API key secure (not exposed in browser JavaScript)
- Handle CORS issues
- Simplify the API interaction
API Endpoints
The application creates three proxy endpoints:
- POST /api/retrieve - Submit a retrieval request
- GET /api/status/{requestId} - Poll for retrieval status
- GET /api/content/{requestId} - Download the page content
Workflow
- User enters API key and URL
- WebSample sends request to ViewEngine API
- Polls for status updates every 2 seconds
- When complete, downloads and displays:
- Page metadata
- Thumbnail image
- Full JSON content
Configuration
To use a different ViewEngine API endpoint, edit Program.cs:
const string API_BASE_URL = "https://your-custom-endpoint.com";
For local development with the ViewEngine API running locally:
const string API_BASE_URL = "http://localhost:5072";
Security Notes
- API keys are stored in browser localStorage (client-side only)
- The proxy server never logs or stores API keys
- All requests to ViewEngine API include proper authentication headers
- CORS is enabled to allow browser-based requests
Troubleshooting
"Invalid API key" error
- Verify your API key is correct
- Check that your API key has the
mcp:retrievescope
"Connection error"
- Ensure the ViewEngine API is accessible
- Check your internet connection
- Verify the API_BASE_URL is correct
Results not appearing
- Check browser console for errors
- Verify the job completed successfully
- Ensure the response includes content data
Example URLs to Try
https://example.com- Simple pagehttps://news.google.com- News sitehttps://github.com- GitHub homepagehttps://www.viewengine.io- ViewEngine homepage
Building for Production
dotnet publish -c Release -o ./publish
Then deploy the contents of ./publish to your web server.
License
This sample application is provided as-is for demonstration purposes.