Workers Binding API
VPC Service bindings provide a convenient API for accessing VPC Services from your Worker. Each binding represents a connection to a service in your private network through a Cloudflare Tunnel.
Each request made on the binding will route to the specific service that was configured for the VPC Service, while restricting access to the rest of your private network.
A VPC Service binding is accessed via the env parameter in your Worker's fetch handler. It provides a fetch() method for making HTTP requests to your private service.
Makes an HTTP request to the private service through the configured tunnel.
const response = await env.VPC_SERVICE_BINDING.fetch(resource, options);resource(string | URL | Request) - The URL to fetch. This must be an absolute URL including protocol, host, and path (for example,http://internal-api/api/users)options(optional RequestInit) - Standard fetch options including:method- HTTP method (GET, POST, PUT, DELETE, etc.)headers- Request headersbody- Request bodysignal- AbortSignal for request cancellation
Returns a Promise<Response> that resolves to a standard Fetch API Response object ↗.
export default { async fetch(request, env) { const privateRequest = new Request( "http://internal-api.company.local/users", ); const response = await env.VPC_SERVICE_BINDING.fetch(privateRequest); const users = await response.json();
return new Response(JSON.stringify(users), { headers: { "Content-Type": "application/json" }, }); },};export default { async fetch(request, env) { const privateRequest = new Request( "http://internal-api.company.local/users", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${env.API_TOKEN}`, }, body: JSON.stringify({ name: "John Doe", email: "john@example.com", }), }, );
const response = await env.VPC_SERVICE_BINDING.fetch(privateRequest);
if (!response.ok) { return new Response("Failed to create user", { status: response.status }); }
const user = await response.json(); return new Response(JSON.stringify(user), { headers: { "Content-Type": "application/json" }, }); },};export default { async fetch(request, env) { const privateRequest = new Request("https://10.0.1.50/api/data"); const response = await env.VPC_SERVICE_BINDING.fetch(privateRequest);
return response; },};- Configure service bindings in wrangler.toml
- Refer to usage examples
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-