Introduction
Small TypeScript packages for building HTTP services on the Fetch API. Each solves one problem and can be used without the others.
edgetime is a set of small TypeScript packages for building HTTP services on the Fetch API. They run on Cloudflare Workers, Node, Deno and Bun. Each package solves one problem and can be used without the others.
Packages
Section titled “Packages”| Package | What it gives you | Runtime dependencies |
|---|---|---|
@edgetime/router |
Request router, middleware pipeline, typed per-request context, host dispatch | none |
@edgetime/http |
Problem-details errors, size-limited body readers, cookies, conditional and range requests, schema validation | none |
@edgetime/log |
Structured JSON logger with child loggers and redaction | none |
@edgetime/config |
Strict boolean flags and required variables | none |
@edgetime/resilience |
Retry with backoff, bounded concurrency, fallback reads, replicated writes | none |
@edgetime/middleware |
Request ID, access log, CORS, security headers, cross-origin write protection, rate limiting | none |
@edgetime/auth |
Sealed tokens, bearer and OAuth resource-server helpers, scope checks | none |
@edgetime/auth/jwt, @edgetime/auth/session |
JWT verification, encrypted cookie sessions | jose |
@edgetime/cloudflare |
Queue consumers, Cache API read-through, Turnstile verification | @edgetime/resilience |
@edgetime/cloudflare/access |
Cloudflare Access token verification | jose, through @edgetime/auth/jwt |
@edgetime/cloudflare/durable |
Strict rate limiter as a Durable Object | none (Workers only) |
@edgetime/node |
Serves a fetch handler on Node’s HTTP server | none (Node only) |
The router is about 4 kB gzipped; a Worker using every package, jose included, is about 20 kB gzipped. Every entry point is tree-shakeable: named exports only, and no side effects on import.
A complete service
Section titled “A complete service”import { type AuthInfo, requireScopes } from '@edgetime/auth';import { createJwtVerifier, jwtAuth } from '@edgetime/auth/jwt';import { connectingIp } from '@edgetime/cloudflare';import { errorHandler, HttpError, readJson } from '@edgetime/http';import { createLogger } from '@edgetime/log';import { accessLog, rateLimit, requestId, secureHeaders } from '@edgetime/middleware';import { perEnv, Router } from '@edgetime/router';
type App = { env: Env; ctx: ExecutionContext; vars: { requestId: string; auth: AuthInfo };};
const verifier = perEnv((env: Env) => createJwtVerifier({ keys: { jwksUrl: `${env.ISSUER}/.well-known/jwks.json` }, issuer: env.ISSUER, audience: env.AUDIENCE, }),);
const api = new Router<App>() .use(jwtAuth<App>({ verifier: (c) => verifier(c.env) })) .get('/orders/:id', async (c) => { const order = await c.env.ORDERS.get(c.params.id, 'json'); if (!order) throw new HttpError(404, 'No such order'); return c.json(order); }) .post('/orders', requireScopes('orders:write'), async (c) => { const input = await readJson(c.req, { limit: 16 * 1024 }); return c.json({ received: input }, 201); });
const app = new Router<App>() .use( requestId(), accessLog({ logger: createLogger({ base: { service: 'orders' } }) }), secureHeaders(), ) .use( '/v1', rateLimit<App>({ limiter: (c) => c.env.API_LIMIT, key: (c) => connectingIp(c.req) }), ) .get('/health', (c) => c.json({ status: 'ok' })) .mount('/v1', api) .onError(errorHandler({ extensions: (c) => ({ requestId: c.get('requestId') }) }));
export default { fetch: app.fetch } satisfies ExportedHandler<Env>;examples/api in the
repository is a complete Worker built this way, with tests that run inside the Workers runtime.
examples/node runs the same
routes on Node with in-process adapters.
Requirements
Section titled “Requirements”The packages need a runtime with the Fetch API and Web Crypto. @edgetime/node needs Node 24.13
or later. Types are written for TypeScript’s strict mode.