JavaScript Examples
JavaScript and TypeScript examples for using the PageSight API.
Basic Request with Fetch API
The simplest way to make a request using the native Fetch API.
With Error Handling
Proper error handling for production applications.
Request with Categories
Extract specific data categories from a webpage.
Custom Cache Duration (Pro Only)
Set cache duration to 30 minutes. Minimum is 5 minutes for Pro users.
Cache Revalidation (Pro Only)
Force a fresh scrape by bypassing the cache.
Using Axios
Example using the Axios library for HTTP requests.
React Custom Hook
A reusable React hook for fetching page data.
Tips & Best Practices
• Always use encodeURIComponent() for URLs
• Store API keys in environment variables
• Implement proper error handling
• Check response status before parsing JSON
• Use async/await for cleaner code
• Don't hardcode API keys in your code
• Don't ignore error responses
• Don't forget to handle network errors
• Don't make requests without rate limit checks
• Don't use eval() with API responses
PageSight