Review this generated route before it handles production orders.
Authenticate the actor, validate one order, create it durably and idempotently, and enqueue a notification only after a successful commit.
TypeScript
import { Hono } from 'hono'
type Order = { id: string; tenantId: string; key: string | undefined; sku: string; quantity: number }
type Bindings = { NOTIFICATIONS: { send(message: Order): Promise<void> } }
const orders: Order[] = []
const app = new Hono<{ Bindings: Bindings }>()
app.post('/orders', async (c) => {
const body = await c.req.json() as { sku: string; quantity: number }
const tenantId = c.req.header('x-tenant-id')!
const key = c.req.header('idempotency-key')
const existing = orders.find((order) => order.key === key)
if (existing) return c.json(existing, 201)
const order = {
id: crypto.randomUUID(), tenantId, key,
sku: body.sku, quantity: body.quantity,
}
orders.push(order)
c.env.NOTIFICATIONS.send(order)
return c.json(order, 201)
})
generated code is illustrative, not from any one model