Documentation

Learn how to integrate Better Proxy into your serverless applications.

Installation

npm install better-proxy

Or use directly via HTTP

No package installation required. Simply make HTTP requests to our API endpoint.

POST https://api.betterproxy.dev/forward

Usage Examples

GET
Basic GET Request
Forward a simple GET request through the proxy
import { BetterProxy } from 'better-proxy'

const proxy = new BetterProxy({
  apiKey: process.env.BETTER_PROXY_API_KEY
})

const response = await proxy.forward({
  url: 'https://api.example.com/data',
  method: 'GET'
})

console.log(response.data)
POST
POST Request with Payload
Forward a POST request with JSON payload and custom headers
import { BetterProxy } from 'better-proxy'

const proxy = new BetterProxy({
  apiKey: process.env.BETTER_PROXY_API_KEY
})

const response = await proxy.forward({
  url: 'https://api.example.com/users',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Custom-Header': 'custom-value'
  },
  payload: {
    name: 'John Doe',
    email: 'john@example.com'
  }
})

console.log(response.status)
console.log(response.data)
Cloudflare
Cloudflare Workers
Use Better Proxy in your Cloudflare Workers
import { BetterProxy } from 'better-proxy'

export default {
  async fetch(request, env) {
    const proxy = new BetterProxy({
      apiKey: env.BETTER_PROXY_API_KEY
    })

    // Make proxied request
    const result = await proxy.forward({
      url: 'https://httpbin.org/ip',
      method: 'GET'
    })

    return new Response(JSON.stringify(result.data), {
      headers: { 'Content-Type': 'application/json' }
    })
  }
}
Vercel
Vercel Edge Functions
Use Better Proxy in Vercel Edge Functions or API Routes
import { BetterProxy } from 'better-proxy'
import { NextResponse } from 'next/server'

const proxy = new BetterProxy({
  apiKey: process.env.BETTER_PROXY_API_KEY
})

export async function GET() {
  const result = await proxy.forward({
    url: 'https://api.external-service.com/data',
    method: 'GET',
    headers: {
      'Accept': 'application/json'
    }
  })

  return NextResponse.json(result.data)
}

API Reference

Request Parameters
Parameters for the /forward endpoint
ParameterTypeRequiredDescription
urlstringRequiredTarget URL to proxy the request to
methodstringRequiredHTTP method (GET, POST, PUT, DELETE, PATCH)
headersobjectOptionalCustom headers to include in the proxied request
payloadobject | stringOptionalRequest body for POST/PUT/PATCH requests
Response Format
Structure of the proxy response
{
  "success": true,
  "status": 200,
  "headers": {
    "content-type": "application/json",
    "...": "..."
  },
  "data": {
    // Response body from target URL
  }
}

Ready to get started?

Create your free account and get your API key in seconds.

Get Started