
Wrangler Has a Free API — Here's How to Deploy Cloudflare Workers from CLI
Wrangler is the CLI for Cloudflare Workers — the serverless platform that runs at the edge in 300+ cities. The free tier includes 100K requests/day, making it perfect for APIs and microservices. Installation npm install -g wrangler wrangler login Create a Worker npm create cloudflare@latest my-worker cd my-worker Worker Code // src/index.ts export default { async fetch ( request : Request , env : Env ): Promise < Response > { const url = new URL ( request . url ); if ( url . pathname === " /api/hello " ) { return Response . json ({ message : " Hello from the edge! " }); } if ( url . pathname === " /api/scrape " && request . method === " POST " ) { const { targetUrl } = await request . json (); const response = await fetch ( targetUrl ); const html = await response . text (); return Response . json ({ length : html . length , status : response . status }); } return new Response ( " Not Found " , { status : 404 }); } }; wrangler.toml Configuration name = "my-worker" main = "src/index.ts"
Continue reading on Dev.to Webdev
Opens in a new tab

