Skip to content

Add Hono example (and decide on Web Headers support) #104

@gmoon

Description

@gmoon

After v4.0 lands (#103), add a Hono example to demonstrate that
`proxy.fetch()` works cleanly with Web Standards runtimes
(Bun, Workers, Deno) where Hono is the de facto framework.

Why

The v4 `proxy.fetch()` API was designed pure (no `res` mutation)
specifically so frameworks built around `Web Response` could use it.
Hono is the obvious validation case. The README's "Framework
Compatibility" list doesn't currently include Hono; the example would
back it.

Sketch

```ts
import { Hono } from 'hono';
import { S3Proxy } from 's3proxy';
import type { HttpRequest } from 's3proxy';

const proxy = new S3Proxy({ bucket: 's3proxy-public' });
await proxy.init();

const app = new Hono();

app.get('/health', async (c) => {
await proxy.healthCheck();
return c.text('OK');
});

app.get('*', async (c) => {
const url = new URL(c.req.url);
const { stream, status, headers } = await proxy.fetch({
url: url.pathname + url.search,
method: c.req.method,
headers: Object.fromEntries(c.req.raw.headers),
} as HttpRequest);
return new Response(stream as unknown as ReadableStream, { status, headers });
});

export default app;
```

The decision point

Hono passes a `Web Request` whose `.headers` is a `Headers`
object (iterable, not a `Record`). The example above adapts via
`Object.fromEntries(headers)`. That works, but it's friction.

Two paths:

A. Document the adapter pattern in the example. Cheap. The
adapter is one line. Hono users copy-paste it once. The library stays
focused on `Record<string, string | string[]>`-shaped headers.

B. Widen `HttpRequest['headers']` to accept `Headers | Record<...>`,
and have `mapHeaderToParam` handle both. More invasive — the parser
and any extension package now has two header shapes to think about.

I'd lean (A) unless the friction shows up in more than just Hono. If
SvelteKit / Remix / Vercel functions all need similar adapters,
(B) starts to look right.

Definition of done

  • `examples/hono-basic.ts` running via `tsx` against `s3proxy-public`.
  • Smoke gate (`scripts/smoke-examples.sh`) extended to cover it.
  • README "Framework Compatibility" list adds Hono with a ✅.
  • A short paragraph in README documenting the adapter pattern.
  • If we go with (B), follow-up PR widens the type and updates parser tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions