Documentation
CORSPORXY Logo

Documentation → general

Usage Examples

Create an account in the dashboard, then replace YOUR_API_KEY with your CORSPROXY key in every example. Encode the target URL, including any query parameters, with encodeURIComponent() or URLSearchParams.

Free accounts support browser API requests and raw RSS/Atom feeds. Hobby adds raw image delivery; Production adds conversion, extraction, header rewrites, caching controls, and server-side requests. Register the domain of the app making browser requests, rather than the target API or feed. Test your URL in the playground.

1. Simple API Request

fetch('https://corsproxy.io/?key=YOUR_API_KEY&url=https://jsonplaceholder.typicode.com/posts/1')
  .then(response => response.json())
  .then(data => console.log(data));

2. POST Request with JSON

fetch('https://corsproxy.io/?key=YOUR_API_KEY&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

fetch('https://corsproxy.io/?key=YOUR_API_KEY&url=https://api.example.com/data', {
  headers: {
    'Authorization': 'Bearer UPSTREAM_API_TOKEN',
    'Accept': 'application/json'
  }
})
.then(response => response.json())
.then(data => console.log(data));

4. Convert CSV/XML/RSS to JSON (Production plan)

// CSV -> JSON
fetch('https://corsproxy.io/?key=YOUR_API_KEY&url=https://example.com/data.csv&input=csv&output=json')
  .then(res => res.json())
  .then(data => console.log(data));

// XML -> JSON
fetch('https://corsproxy.io/?key=YOUR_API_KEY&url=https://example.com/data.xml&input=xml&output=json')
  .then(res => res.json())
  .then(data => console.log(data));

// RSS -> JSON: entries are in data.rss.channel.item, not data.items
fetch('https://corsproxy.io/?key=YOUR_API_KEY&url=https://example.com/feed.xml&input=rss&output=json')
  .then(res => res.json())
  .then(data => console.log(data));

See the RSS & Feeds guide for entry parsing and a complete React example.

5. Content Extraction (Production plan)

// Extract main content with a CSS selector
fetch('https://corsproxy.io/?key=YOUR_API_KEY&url=https://news.ycombinator.com&extract=1&selector=.titleline%20%3E%20a')
  .then(res => res.json())
  .then(data => console.log(data));

// Plain-text output
fetch('https://corsproxy.io/?key=YOUR_API_KEY&url=https://example.com&extract=1&format=text')
  .then(res => res.text())
  .then(text => console.log(text));

6. Image Downloads (Hobby or higher; plan size limits apply)

fetch('https://corsproxy.io/?key=YOUR_API_KEY&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();
  });

7. GraphQL Queries

const query = `
  query {
    user(id: "123") {
      name
      email
    }
  }
`;

fetch('https://corsproxy.io/?key=YOUR_API_KEY&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));