Cloudflare Workers
ActiveServer-side validation in a Worker — @postio/core uses native fetch, no Node polyfills.
Install
npm i @postio/core
30-second example
// src/index.ts (Worker entry)
import { Postio } from '@postio/core';
interface Env { POSTIO_API_KEY: string }
export default {
async fetch(req: Request, env: Env): Promise<Response> {
const url = new URL(req.url);
const postcode = url.searchParams.get('postcode');
if (!postcode) return new Response('postcode required', { status: 400 });
const postio = new Postio({ apiKey: env.POSTIO_API_KEY });
const { results } = await postio.address.postcode(postcode);
return Response.json(results);
},
};