@zod-schemas/rfc7807
v1.0.1
Published
Zod schema for RFC 7807 Problem Details
Downloads
2,534
Maintainers
Readme
@zod-schemas/rfc7807
Zod schema for RFC 7807 Problem Details for HTTP APIs
Installation
npm install @zod-schemas/rfc7807Usage
import { ProblemDetail } from '@zod-schemas/rfc7807';
// Validate a problem detail object
const result = ProblemDetail.parse({
type: 'https://example.com/probs/out-of-credit',
title: 'You do not have enough credit.',
status: 403,
detail: 'Your current balance is 30, but that costs 50.',
instance: 'https://example.com/account/12345/msgs/abc',
});
// Use as a TypeScript type
import type { ProblemDetail } from '@zod-schemas/rfc7807';
const problem: ProblemDetail = {
status: 404,
title: 'Not Found',
};RFC 7807 Overview
RFC 7807 defines a "problem detail" as a way to carry machine-readable details of errors in HTTP responses. The schema includes the following optional fields:
- type: A URI reference identifying the problem type
- title: A short, human-readable summary of the problem type
- status: The HTTP status code
- detail: A human-readable explanation specific to this occurrence
- instance: A URI reference identifying the specific occurrence of the problem
References
License
MIT
