Documentation → general
Usage Examples
1. Simple API Request
fetch('https://corsproxy.io/?url=https://jsonplaceholder.typicode.com/posts/1')
.then(response => response.json())
.then(data => console.log(data));
2. POST Request with Data
fetch('https://corsproxy.io/?url=https://api.example.com/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'John Doe',
email: 'john@example.com'
})
})
.then(response => response.json())
.then(data => console.log(data));
3. API with Authentication Headers
// OpenAI API example
fetch('https://corsproxy.io/?url=https://api.openai.com/v1/models', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'OpenAI-Organization': 'YOUR_ORG_ID'
}
})
.then(response => response.json())
.then(data => console.log(data));
// Generic API with custom headers
fetch('https://corsproxy.io/?url=https://example.com/api', {
headers: {
'X-API-Key': 'your-api-key',
'X-Custom-Header': 'custom-value',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data));
4. Large File Downloads
// Download large files (images, datasets, documents)
fetch('https://corsproxy.io/?url=https://example.com/large-image.jpg')
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'image.jpg';
a.click();
});
// For video files - use the enhanced video endpoint (Streaming plan required)
fetch('https://video.corsproxy.io/?url=https://example.com/video.mp4')
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
const video = document.createElement('video');
video.src = url;
video.controls = true;
document.body.appendChild(video);
});
5. GraphQL Queries
const query = `
query {
user(id: "123") {
name
email
}
}
`;
fetch('https://corsproxy.io/?url=https://api.example.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN'
},
body: JSON.stringify({ query })
})
.then(response => response.json())
.then(data => console.log(data));
6. Form Data Upload
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('description', 'My uploaded file');
fetch('https://corsproxy.io/?url=https://api.example.com/upload', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
},
body: formData
})
.then(response => response.json())
.then(data => console.log(data));