Posts

Showing posts with the label Cloudflare

Cloudflare Workers Tutorial: Build a Fast Orders API

Image
Quick answer Cloudflare Workers runs small JavaScript or TypeScript functions on Cloudflare's edge network, close to the person making the request, with no server to manage. You write a fetch handler, test it locally with Wrangler, and the same code answers from data centres around the world. This post builds a small orders API for a Karachi shop and fixes the bug that bites almost every first Worker. A clothing shop in Karachi takes orders on WhatsApp and writes them in a notebook. The owner wants an orders page on the shop website, so customers can order without messaging first. The site sits on cheap shared hosting overseas, and the page loads slowly at peak hours. The owner wants no server to patch and no monthly bill for traffic the shop does not have yet. A tiny API that answers in milliseconds and costs nothing at this scale is the right shape for the problem. What a Worker actually is A Worker is a function that runs when a request arrives. You export an object with a f...