Skip to content

Thereallo1026/fetch-worker

Repository files navigation

Fetch Worker

Deploy to Cloudflare

Features

  • Execute fetch requests using JSON configuration
  • Automatic handling of JSON request/response bodies
  • CORS support built-in
  • Detailed response information including headers and status
  • Handles both JSON and non-JSON responses
  • User-friendly error messages
  • Interactive documentation when accessed via browser

Usage

Send a POST request to your worker's URL with a JSON payload containing your fetch configuration:

const response = await fetch('https://fetch-worker.your-subdomain.workers.dev/', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://api.example.com/data',
    method: 'GET',
    headers: {
      'Authorization': 'Bearer YOUR_TOKEN'
    }
  })
});

const result = await response.json();

Response Format

The worker returns a standardized JSON response:

{
  "success": true,
  "status": 200,
  "statusText": "OK",
  "headers": {
    "content-type": "application/json",
    // ... other headers
  },
  "data": {
    // Response data from the target API
  }
}

Error Handling

If there's an error, you'll receive a response like:

{
  "success": false,
  "error": "Error message describing what went wrong"
}

Development

This project uses Bun as the JavaScript runtime.

Prerequisites

Setup

  1. Clone the repository
  2. Install dependencies:
    bun install

Available Commands

  • bun run dev - Start a local development server
  • bun run deploy - Deploy to Cloudflare
  • bun run test - Run tests

Configuration

The worker can be configured through wrangler.jsonc. See Cloudflare's documentation for more details.

License

MIT

About

A Cloudflare Worker that acts as a fetch API proxy/debugger.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published