@zio.dev/zio-blocks 0.0.33 → 0.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adr/2026-07-18-data-migration.md +123 -0
- package/guides/async-getting-started.md +687 -0
- package/guides/compile-time-resource-safety-with-scope.md +21 -16
- package/guides/getting-started-with-mux.md +1395 -0
- package/guides/query-dsl-extending.md +161 -102
- package/guides/query-dsl-fluent-builder.md +217 -157
- package/guides/query-dsl-reified-optics.md +12 -10
- package/guides/query-dsl-sql.md +640 -165
- package/guides/sql-checked-interpolation.md +173 -0
- package/guides/sql-transactions.md +286 -0
- package/guides/telemetry-guide.md +1130 -0
- package/guides/zio-schema-migration.md +29 -22
- package/index.md +248 -389
- package/package.json +1 -1
- package/plans/config-follow-up-prs.md +188 -0
- package/plans/config-pr-assessment-roadmap.md +310 -0
- package/reference/MuxDataFlow.jsx +250 -0
- package/reference/async.md +1499 -0
- package/reference/chunk.md +3533 -308
- package/reference/codegen/case-class.md +436 -0
- package/reference/codegen/emitter-config.md +383 -0
- package/reference/codegen/examples.md +664 -0
- package/reference/codegen/field.md +316 -0
- package/reference/codegen/index.md +317 -0
- package/reference/codegen/scala-emitter.md +392 -0
- package/reference/codegen/scala-file.md +276 -0
- package/reference/codegen/sealed-trait.md +408 -0
- package/reference/codegen/type-definition.md +340 -0
- package/reference/codegen/type-ref.md +201 -0
- package/reference/combinators.md +347 -117
- package/reference/config/config-decoder.md +460 -0
- package/reference/config/config-source.md +489 -0
- package/reference/config/errors.md +278 -0
- package/reference/config/flags.md +369 -0
- package/reference/config/formats.md +314 -0
- package/reference/config/index.md +304 -0
- package/reference/config/rollout.md +336 -0
- package/reference/context.md +9 -52
- package/reference/data-migration.md +269 -0
- package/reference/datastar/attributes.md +302 -0
- package/reference/datastar/events.md +234 -0
- package/reference/datastar/index.md +256 -0
- package/reference/datastar/signals.md +230 -0
- package/reference/datastar/sse.md +295 -0
- package/reference/datastar.md +346 -0
- package/reference/docs.md +1461 -345
- package/reference/endpoint/auth-type.md +146 -0
- package/reference/endpoint/bulk-creation.md +96 -0
- package/reference/endpoint/endpoint.md +297 -0
- package/reference/endpoint/http-codec.md +249 -0
- package/reference/endpoint/index.md +745 -0
- package/reference/endpoint/path-codec.md +225 -0
- package/reference/endpoint/route-pattern.md +194 -0
- package/reference/endpoint/route-tree.md +111 -0
- package/reference/endpoint/segment-codec.md +199 -0
- package/reference/html.md +1424 -0
- package/reference/htmx/attribute-values.md +359 -0
- package/reference/htmx/hx-encoding.md +111 -0
- package/reference/htmx/hx-params.md +204 -0
- package/reference/htmx/hx-swap.md +276 -0
- package/reference/htmx/hx-sync.md +251 -0
- package/reference/htmx/hx-target.md +314 -0
- package/reference/htmx/hx-trigger.md +457 -0
- package/reference/htmx/hx-url-update.md +239 -0
- package/reference/htmx/index.md +807 -0
- package/reference/htmx/response-headers.md +240 -0
- package/reference/http-model/headers.md +735 -0
- package/reference/http-model/index.md +49 -0
- package/reference/http-model/model.md +1517 -0
- package/reference/http-model/schema-codecs.md +522 -0
- package/reference/http-model/schema.md +750 -0
- package/reference/http-model/server-sent-event.md +341 -0
- package/reference/jwt.md +195 -0
- package/reference/maybe.md +943 -0
- package/reference/media-type.md +2 -2
- package/reference/mux.md +254 -0
- package/reference/mux.mdx +828 -0
- package/reference/openapi.md +1351 -0
- package/reference/projection.md +654 -0
- package/reference/resource-management/defer-handle.md +1 -1
- package/reference/resource-management/resource.md +31 -98
- package/reference/resource-management/scope.md +28 -220
- package/reference/resource-management/wire.md +5 -55
- package/reference/ringbuffer/MpmcDiagram.jsx +717 -0
- package/reference/ringbuffer/MpscDiagram.jsx +618 -0
- package/reference/ringbuffer/SpmcDiagram.jsx +680 -0
- package/reference/ringbuffer/SpscDiagram.jsx +677 -0
- package/reference/ringbuffer/advanced.mdx +109 -0
- package/reference/ringbuffer/index.mdx +145 -0
- package/reference/ringbuffer/mpmc.mdx +185 -0
- package/reference/ringbuffer/mpsc.mdx +164 -0
- package/reference/ringbuffer/spmc.mdx +108 -0
- package/reference/ringbuffer/spsc.mdx +416 -0
- package/reference/{allows.md → schema/allows.md} +4 -100
- package/reference/{binding-resolver.md → schema/binding-resolver.md} +1 -1
- package/reference/{binding.md → schema/binding.md} +3 -4
- package/reference/schema/built-in-codecs/avro.md +451 -0
- package/reference/schema/built-in-codecs/bson.md +510 -0
- package/reference/schema/built-in-codecs/csv.md +564 -0
- package/reference/schema/built-in-codecs/index.md +77 -0
- package/reference/schema/built-in-codecs/json/index.md +295 -0
- package/reference/schema/built-in-codecs/json/json-config.md +217 -0
- package/reference/{json-patch.md → schema/built-in-codecs/json/json-patch.md} +5 -5
- package/reference/{json-schema.md → schema/built-in-codecs/json/json-schema.md} +14 -47
- package/reference/schema/built-in-codecs/json/json-selection.md +322 -0
- package/reference/{json.md → schema/built-in-codecs/json/json.md} +32 -64
- package/reference/schema/built-in-codecs/messagepack.md +508 -0
- package/reference/schema/built-in-codecs/thrift.md +433 -0
- package/reference/schema/built-in-codecs/toon.md +1078 -0
- package/reference/{xml.md → schema/built-in-codecs/xml.md} +13 -9
- package/reference/schema/built-in-codecs/yaml.md +552 -0
- package/reference/{codec.md → schema/codec.md} +11 -11
- package/reference/{dynamic-optic.md → schema/dynamic-optic.md} +196 -5
- package/reference/{dynamic-schema.md → schema/dynamic-schema.md} +8 -8
- package/reference/schema/format.md +92 -0
- package/reference/schema/index.md +52 -0
- package/reference/schema/migration.md +297 -0
- package/reference/{modifier.md → schema/modifier.md} +58 -7
- package/reference/{optics.md → schema/optics.md} +2 -2
- package/reference/{patch.md → schema/patch.md} +1 -1
- package/{path-interpolator.md → reference/schema/path-interpolator.md} +167 -72
- package/reference/schema/reflect-transformer.md +140 -0
- package/reference/{schema-evolution → schema/schema-evolution}/as.md +8 -8
- package/reference/{schema-evolution → schema/schema-evolution}/index.md +2 -2
- package/reference/{schema-evolution → schema/schema-evolution}/into.md +8 -8
- package/reference/{schema-expr.md → schema/schema-expr.md} +110 -175
- package/reference/schema/schema-search.md +263 -0
- package/reference/{schema.md → schema/schema.md} +22 -2
- package/reference/{structural-types.md → schema/structural-types.md} +1 -1
- package/reference/{type-class-derivation.md → schema/type-class-derivation.md} +63 -1
- package/reference/smithy.md +1032 -0
- package/reference/sql/db-codec-deriver.md +71 -0
- package/reference/sql/db-codec.md +687 -0
- package/reference/sql/db-con.md +271 -0
- package/reference/sql/db-connection.md +153 -0
- package/reference/sql/db-param-writer.md +77 -0
- package/reference/sql/db-param.md +66 -0
- package/reference/sql/db-result-reader.md +148 -0
- package/reference/sql/db-tx.md +114 -0
- package/reference/sql/db-value.md +41 -0
- package/reference/sql/ddl.md +85 -0
- package/reference/sql/frag.md +288 -0
- package/reference/sql/index.md +341 -0
- package/reference/sql/repo.md +600 -0
- package/reference/sql/sql-dialect.md +73 -0
- package/reference/sql/sql-logger.md +62 -0
- package/reference/sql/sql-name-mapper.md +70 -0
- package/reference/sql/table-metadata.md +134 -0
- package/reference/sql/table.md +448 -0
- package/reference/sql/transactor-zio.md +399 -0
- package/reference/sql/transactor.md +363 -0
- package/reference/sql-zio.md +112 -0
- package/reference/streams/core/index.md +32 -0
- package/reference/streams/core/pipeline.md +854 -0
- package/reference/streams/core/sink.md +1404 -0
- package/reference/streams/core/stream.md +3236 -0
- package/reference/streams/execution-and-compatibility/async-execution.md +822 -0
- package/reference/streams/execution-and-compatibility/index.md +35 -0
- package/reference/streams/execution-and-compatibility/platform-differences.md +297 -0
- package/reference/streams/execution-and-compatibility/scala-2-compatibility.md +88 -0
- package/reference/streams/execution-and-compatibility/zero-boxing.md +393 -0
- package/reference/streams/index.md +726 -0
- package/reference/streams/primitives/index.md +30 -0
- package/reference/streams/primitives/reader.md +1992 -0
- package/reference/streams/primitives/writer.md +1201 -0
- package/reference/telemetry/common/any-value.md +90 -0
- package/reference/telemetry/common/attribute-key.md +87 -0
- package/reference/telemetry/common/attributes.md +118 -0
- package/reference/telemetry/common/index.md +39 -0
- package/reference/telemetry/common/instrumentation-scope.md +24 -0
- package/reference/telemetry/common/resource.md +34 -0
- package/reference/telemetry/index.md +311 -0
- package/reference/telemetry/logging/index.md +197 -0
- package/reference/telemetry/logging/log-enrichment.md +72 -0
- package/reference/telemetry/logging/log-formatter.md +100 -0
- package/reference/telemetry/logging/log-record-processor.md +56 -0
- package/reference/telemetry/logging/log-record.md +44 -0
- package/reference/telemetry/logging/log-writer.md +64 -0
- package/reference/telemetry/logging/logger-provider.md +142 -0
- package/reference/telemetry/logging/logger.md +83 -0
- package/reference/telemetry/logging/severity.md +62 -0
- package/reference/telemetry/metrics/index.md +150 -0
- package/reference/telemetry/metrics/instruments.md +183 -0
- package/reference/telemetry/metrics/labeled-instruments.md +74 -0
- package/reference/telemetry/metrics/meter-provider.md +76 -0
- package/reference/telemetry/metrics/meter.md +98 -0
- package/reference/telemetry/metrics/metric-data.md +57 -0
- package/reference/telemetry/otel/custom-exporter.md +216 -0
- package/reference/telemetry/otel/index.md +212 -0
- package/reference/telemetry/tracing/index.md +155 -0
- package/reference/telemetry/tracing/sampler.md +89 -0
- package/reference/telemetry/tracing/span-builder.md +57 -0
- package/reference/telemetry/tracing/span-context.md +39 -0
- package/reference/telemetry/tracing/span-data.md +32 -0
- package/reference/telemetry/tracing/span-kind.md +55 -0
- package/reference/telemetry/tracing/span-processor.md +53 -0
- package/reference/telemetry/tracing/span-status.md +47 -0
- package/reference/telemetry/tracing/span.md +117 -0
- package/reference/telemetry/tracing/tracer-provider.md +91 -0
- package/reference/telemetry/tracing/tracer.md +52 -0
- package/reference/typeid.md +5 -83
- package/sidebars.js +376 -43
- package/undocumented-report.md +528 -270
- package/reference/formats.md +0 -694
- package/reference/http-model.md +0 -1716
- package/reference/streams.md +0 -989
- package/ringbuffer.md +0 -249
- /package/reference/{json-differ.md → schema/built-in-codecs/json/json-differ.md} +0 -0
- /package/reference/{dynamic-value.md → schema/dynamic-value.md} +0 -0
- /package/reference/{lazy.md → schema/lazy.md} +0 -0
- /package/reference/{reflect.md → schema/reflect.md} +0 -0
- /package/reference/{registers.md → schema/registers.md} +0 -0
- /package/reference/{schema-error.md → schema/schema-error.md} +0 -0
- /package/reference/{syntax.md → schema/syntax.md} +0 -0
- /package/reference/{validation.md → schema/validation.md} +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: http-codec
|
|
3
|
+
title: "HttpCodec"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
`HttpCodec[K, A]` is a composable, typed descriptor for HTTP request and response parts. The phantom type parameter `K` (either `CodecKind.Request` or `CodecKind.Response`) tracks which direction the codec belongs to, so the compiler prevents mixing request-side codecs (query, request header, request body) with response-side codecs (status, response header, response body). The trait signature is:
|
|
7
|
+
|
|
8
|
+
```scala
|
|
9
|
+
sealed trait HttpCodec[+K <: CodecKind, A]
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Motivation
|
|
13
|
+
|
|
14
|
+
HTTP surfaces have two directions — request and response — and each direction has several distinct parts. Without static direction tracking, it is easy to accidentally pass a response status codec where a request header codec is expected, or combine a query parameter with a response body.
|
|
15
|
+
|
|
16
|
+
`HttpCodec` makes that class of mistake a compile error. The phantom type `K` carries direction at the type level, so `HttpCodec[CodecKind.Request, A]` and `HttpCodec[CodecKind.Response, A]` are incompatible types. All combinators (`++`, `|`) preserve this constraint: combining two request codecs yields a request codec, and combining request with response is a type error.
|
|
17
|
+
|
|
18
|
+
## `CodecKind`
|
|
19
|
+
|
|
20
|
+
`CodecKind` is a phantom type hierarchy with two sealed subtypes:
|
|
21
|
+
|
|
22
|
+
```scala
|
|
23
|
+
sealed trait CodecKind
|
|
24
|
+
|
|
25
|
+
object CodecKind {
|
|
26
|
+
sealed trait Request extends CodecKind // query, request header, request body
|
|
27
|
+
sealed trait Response extends CodecKind // status, response header, response body
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
These are never instantiated — they exist only to parameterize `HttpCodec[K, A]` at the type level.
|
|
32
|
+
|
|
33
|
+
## Structure
|
|
34
|
+
|
|
35
|
+
`HttpCodec` is an ADT with seven node types:
|
|
36
|
+
|
|
37
|
+
| Node | Kind | Carries |
|
|
38
|
+
| ------------- | --------- | ---------------------------------------------------- |
|
|
39
|
+
| `Empty` | both | No data — neutral element for `++` |
|
|
40
|
+
| `Combine` | both | Two codecs composed sequentially with `++` |
|
|
41
|
+
| `Fallback` | both | Two codecs composed as alternatives with `|` |
|
|
42
|
+
| `Query` | `Request` | Named query parameter with `Schema[A]` |
|
|
43
|
+
| `Header` | both | Named HTTP header with `Schema[A]` (request or response) |
|
|
44
|
+
| `Body` | both | Request or response body with `Schema[A]` |
|
|
45
|
+
| `StatusCodec` | `Response`| HTTP status code |
|
|
46
|
+
|
|
47
|
+
## Construction
|
|
48
|
+
|
|
49
|
+
Smart constructors on the `HttpCodec` companion build each atom type. Choose the constructor that matches the HTTP part you are describing.
|
|
50
|
+
|
|
51
|
+
### Query parameters
|
|
52
|
+
|
|
53
|
+
To describe a named query parameter, use `HttpCodec.query`:
|
|
54
|
+
|
|
55
|
+
```scala
|
|
56
|
+
import zio.blocks.endpoint._
|
|
57
|
+
import zio.blocks.schema.Schema
|
|
58
|
+
|
|
59
|
+
val limitCodec: HttpCodec.Query[Int] = HttpCodec.query("limit", Schema.int)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Optional fields on `Query` include `default`, `doc`, `examples`, and `deprecated`. To create a query codec with a default value:
|
|
63
|
+
|
|
64
|
+
```scala
|
|
65
|
+
import zio.blocks.endpoint._
|
|
66
|
+
import zio.blocks.schema.Schema
|
|
67
|
+
|
|
68
|
+
val pageCodec = HttpCodec.query("page", Schema.int, default = Some(1))
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Request headers
|
|
72
|
+
|
|
73
|
+
To describe a request header by name and schema, use `HttpCodec.requestHeader`:
|
|
74
|
+
|
|
75
|
+
```scala
|
|
76
|
+
import zio.blocks.endpoint._
|
|
77
|
+
import zio.blocks.schema.Schema
|
|
78
|
+
|
|
79
|
+
val traceHeader: HttpCodec.Header[CodecKind.Request, String] =
|
|
80
|
+
HttpCodec.requestHeader("X-Trace-Id", Schema.string)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
To use a zio-http typed header instance (which provides its own name and parse/render logic), pass the typed header directly:
|
|
84
|
+
|
|
85
|
+
```scala
|
|
86
|
+
import zio.blocks.endpoint._
|
|
87
|
+
import zio.http.Header
|
|
88
|
+
|
|
89
|
+
val authHeader: HttpCodec.Header[CodecKind.Request, Header.Authorization] =
|
|
90
|
+
HttpCodec.requestHeader(Header.Authorization)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Response headers
|
|
94
|
+
|
|
95
|
+
To describe a response header, use `HttpCodec.responseHeader`:
|
|
96
|
+
|
|
97
|
+
```scala
|
|
98
|
+
import zio.blocks.endpoint._
|
|
99
|
+
import zio.blocks.schema.Schema
|
|
100
|
+
|
|
101
|
+
val totalCount: HttpCodec.Header[CodecKind.Response, Int] =
|
|
102
|
+
HttpCodec.responseHeader("X-Total-Count", Schema.int)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Request body
|
|
106
|
+
|
|
107
|
+
To describe a request body, use `HttpCodec.requestBody`:
|
|
108
|
+
|
|
109
|
+
```scala
|
|
110
|
+
import zio.blocks.endpoint._
|
|
111
|
+
import zio.blocks.schema.Schema
|
|
112
|
+
|
|
113
|
+
val body: HttpCodec[CodecKind.Request, String] =
|
|
114
|
+
HttpCodec.requestBody(Schema.string)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
To restrict the accepted content types, pass a `Chunk[MediaType]`:
|
|
118
|
+
|
|
119
|
+
```scala
|
|
120
|
+
import zio.blocks.chunk.Chunk
|
|
121
|
+
import zio.blocks.endpoint._
|
|
122
|
+
import zio.blocks.mediatype.MediaTypes
|
|
123
|
+
import zio.blocks.schema.Schema
|
|
124
|
+
|
|
125
|
+
val jsonBody: HttpCodec[CodecKind.Request, String] =
|
|
126
|
+
HttpCodec.requestBody(Schema.string, mediaTypes = Chunk.single(MediaTypes.application.`json`))
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Response body
|
|
130
|
+
|
|
131
|
+
To describe a response body, use `HttpCodec.responseBody`:
|
|
132
|
+
|
|
133
|
+
```scala
|
|
134
|
+
import zio.blocks.endpoint._
|
|
135
|
+
import zio.blocks.schema.Schema
|
|
136
|
+
|
|
137
|
+
val body: HttpCodec[CodecKind.Response, String] =
|
|
138
|
+
HttpCodec.responseBody(Schema.string)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Status codes
|
|
142
|
+
|
|
143
|
+
To describe a required HTTP status code, use `HttpCodec.status`:
|
|
144
|
+
|
|
145
|
+
```scala
|
|
146
|
+
import zio.blocks.endpoint._
|
|
147
|
+
import zio.http.Status
|
|
148
|
+
|
|
149
|
+
val created: HttpCodec[CodecKind.Response, Unit] = HttpCodec.status(Status.Created)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Predefined status constants are available directly on `HttpCodec`:
|
|
153
|
+
|
|
154
|
+
```scala
|
|
155
|
+
import zio.blocks.endpoint._
|
|
156
|
+
|
|
157
|
+
val ok = HttpCodec.Ok
|
|
158
|
+
val created = HttpCodec.Created
|
|
159
|
+
val notFound = HttpCodec.NotFound
|
|
160
|
+
val badRequest = HttpCodec.BadRequest
|
|
161
|
+
val unauthorized = HttpCodec.Unauthorized
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
For any other status code, use `HttpCodec.CustomStatus(code)`.
|
|
165
|
+
|
|
166
|
+
## Composition
|
|
167
|
+
|
|
168
|
+
Two operators combine `HttpCodec` values: `++` sequences parts within the same direction, while `|` creates alternatives for content negotiation or multi-status responses.
|
|
169
|
+
|
|
170
|
+
### Sequential composition with `++`
|
|
171
|
+
|
|
172
|
+
`++` combines two codecs of the same direction into a single codec whose type is the product of both. The result type is automatically flattened, eliminating `Unit` components and nested tuples:
|
|
173
|
+
|
|
174
|
+
```scala
|
|
175
|
+
import zio.blocks.endpoint._
|
|
176
|
+
import zio.blocks.schema.Schema
|
|
177
|
+
|
|
178
|
+
val queryAndHeader: HttpCodec[CodecKind.Request, (String, Int)] =
|
|
179
|
+
HttpCodec.query("name", Schema.string) ++ HttpCodec.query("age", Schema.int)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The compiler rejects mixing directions — combining a request codec with a response codec is a type error:
|
|
183
|
+
|
|
184
|
+
```scala
|
|
185
|
+
import zio.blocks.endpoint._
|
|
186
|
+
import zio.blocks.schema.Schema
|
|
187
|
+
import zio.http.Status
|
|
188
|
+
|
|
189
|
+
// This would be a compile error:
|
|
190
|
+
// HttpCodec.query("name", Schema.string) ++ HttpCodec.status(Status.Ok)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Alternative composition with `|`
|
|
194
|
+
|
|
195
|
+
`|` combines two codecs as alternatives. The result type is automatically computed as a nested `Either`:
|
|
196
|
+
|
|
197
|
+
```scala
|
|
198
|
+
import zio.blocks.endpoint._
|
|
199
|
+
import zio.blocks.schema.Schema
|
|
200
|
+
import zio.http.Status
|
|
201
|
+
|
|
202
|
+
val okOrCreated =
|
|
203
|
+
(HttpCodec.responseBody(Schema.string) ++ HttpCodec.Ok) |
|
|
204
|
+
(HttpCodec.responseBody(Schema.int) ++ HttpCodec.Created)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Authentication Codecs
|
|
208
|
+
|
|
209
|
+
Pre-built request codecs for common authorization header schemes are available on `HttpCodec`:
|
|
210
|
+
|
|
211
|
+
```scala
|
|
212
|
+
import zio.blocks.endpoint._
|
|
213
|
+
import zio.http.Header
|
|
214
|
+
|
|
215
|
+
val basic: HttpCodec[CodecKind.Request, Header.Authorization.Basic] = HttpCodec.basicAuth
|
|
216
|
+
val bearer: HttpCodec[CodecKind.Request, Header.Authorization.Bearer] = HttpCodec.bearerAuth
|
|
217
|
+
val digest: HttpCodec[CodecKind.Request, Header.Authorization.Digest] = HttpCodec.digestAuth
|
|
218
|
+
val proxy: HttpCodec[CodecKind.Request, Header.ProxyAuthorization] = HttpCodec.proxyAuthorization
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
These codecs use `Schema.transform` internally to parse the raw `Authorization` header string into the typed zio-http auth model, surfacing a `SchemaError` if the scheme does not match.
|
|
222
|
+
|
|
223
|
+
## Metadata Fields
|
|
224
|
+
|
|
225
|
+
Every atom node (`Query`, `Header`, `Body`, `StatusCodec`) carries optional metadata that documentation renderers and OpenAPI generators consume:
|
|
226
|
+
|
|
227
|
+
| Field | Type | Purpose |
|
|
228
|
+
| ------------ | ----------------- | ---------------------------------------------- |
|
|
229
|
+
| `doc` | `Doc` | Free-text description for OpenAPI output |
|
|
230
|
+
| `examples` | `Chunk[(String, A)]` | Example values for the OpenAPI spec |
|
|
231
|
+
| `deprecated` | `Option[Doc]` | Marks the field as deprecated with a message |
|
|
232
|
+
| `default` | `Option[A]` | Default value (query and header only) |
|
|
233
|
+
|
|
234
|
+
To create a query codec with documentation and an example:
|
|
235
|
+
|
|
236
|
+
```scala
|
|
237
|
+
import zio.blocks.chunk.Chunk
|
|
238
|
+
import zio.blocks.docs.Doc
|
|
239
|
+
import zio.blocks.endpoint._
|
|
240
|
+
import zio.blocks.schema.Schema
|
|
241
|
+
|
|
242
|
+
val limitCodec = HttpCodec.query(
|
|
243
|
+
name = "limit",
|
|
244
|
+
schema = Schema.int,
|
|
245
|
+
default = Some(20),
|
|
246
|
+
doc = Doc.empty,
|
|
247
|
+
examples = Chunk("default" -> 20, "max" -> 100)
|
|
248
|
+
)
|
|
249
|
+
```
|