Skip to Content

JavaScript Code Examples

This page provides complete examples for calling the MeowLoad API with JavaScript/Node.js.

πŸš€ Using Fetch API

const apiUrl = "https://api.meowload.net/openapi/extract/post"; const apiKey = "your-api-key-here"; fetch(apiUrl, { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": apiKey, "accept-language": "zh" }, body: JSON.stringify({ url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }) }) .then(response => { if (!response.ok) { return response.json().then(error => { throw new Error(`${response.status}: ${error.message}`); }); } return response.json(); }) .then(data => { console.log(`βœ… Extraction successful! Media count: ${data.medias.length}`); data.medias.forEach(media => { console.log(`- ${media.media_type}: ${media.resource_url}`); }); }) .catch(error => { console.error(`❌ Request failed: ${error.message}`); });

πŸ“¦ Using Axios (Node.js)

npm install axios
const axios = require('axios'); const apiUrl = "https://api.meowload.net/openapi/extract/post"; const apiKey = "your-api-key-here"; axios.post(apiUrl, { url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }, { headers: { "x-api-key": apiKey, "accept-language": "zh" } }) .then(response => { const data = response.data; console.log(`βœ… Extraction successful! Media count: ${data.medias.length}`); }) .catch(error => { if (error.response) { console.error(`- Request failed (${error.response.status}): ${error.response.data.message}`); } else { console.error(`❌ Network error: ${error.message}`); } });

🎯 Using async/await

async function extractPost(url, apiKey) { try { const response = await fetch("https://api.meowload.net/openapi/extract/post", { method: "POST", headers: { "Content-Type": "application/json", "x-api-key": apiKey }, body: JSON.stringify({ url }) }); if (!response.ok) { const error = await response.json(); throw new Error(error.message); } return await response.json(); } catch (error) { console.error(`Extraction failed: ${error.message}`); return null; } } // Usage const result = await extractPost("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "your-api-key-here");