Documentation
Learn how to integrate Better Proxy into your serverless applications.
Installation
Install the client package for your platform
Usage Examples
Code examples for common use cases
API Reference
Full API documentation and parameters
Installation
npm install better-proxyOr use directly via HTTP
No package installation required. Simply make HTTP requests to our API endpoint.
POST https://api.betterproxy.dev/forwardUsage 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| url | string | Required | Target URL to proxy the request to |
| method | string | Required | HTTP method (GET, POST, PUT, DELETE, PATCH) |
| headers | object | Optional | Custom headers to include in the proxied request |
| payload | object | string | Optional | Request 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
}
}