v3.2.0
Typed response maps.
import { $error, $type } from 'rouzer'
import * as http from 'rouzer/http'
export const getUser = http.get('users/:id', {
response: {
200: $type<User>(),
404: $error<{ code: 'NOT_FOUND'; message: string }>(),
},
})Handlers return declared errors with ctx.error:
createRouter().use({ getUser }, {
getUser(ctx) {
if (ctx.path.id === 'missing') {
return ctx.error(404, {
code: 'NOT_FOUND',
message: 'User not found',
})
}
return { id: ctx.path.id, name: 'Ada' }
},
})Clients get typed tuples instead of thrown errors for declared statuses:
const [error, user, status] = await client.getUser({
path: { id: 'missing' },
})Also:
- Add
$error<T>()for declared JSON error responses. - Add
ctx.success(status, body)for choosing explicit declared success statuses. - Support response plugins, including NDJSON, inside response maps.
- Forward extra
RequestInitfields such assignalandcredentialsfrom client calls. - Add runnable typed error response docs and tests.
Response markers are type contracts. Rouzer does not re-validate handler return values at the server boundary; validate data where it enters your server or client code.
Compare: v3.1.0...v3.2.0