Encoding of types
This document describe how the http library interpret TypeSpec built-in types and how to configure
bytes
Default behavior:
bytes
are serialized asbase64
when used inside a model serialized as JSON- In request or response body it represent a binary payload.
note
This behavior is only a specification and MUST be respected by the emitter. The http library DOES NOT automatically apply the @encode("base64")
when used inside a JSON model.
Use @encode
to configure
model Pet {
icon: bytes; // Serialize as base64
@encode(BytesKnownEncoding.base64url) // Serialize as base64url
other: bytes;
}
op read(): Pet;
op download(): bytes; // Return application/octet-stream
op upload(@body data: bytes): void; // Accept application/octet-stream
utcDatetime
and offsetDateTime
Default behavior:
- Encoded as
rfc7231
when used in a header - Encoded as
rfc3339
otherwise.
note
This behavior is only a specification and MUST be respected by the emitter. The http library DOES NOT automatically apply the @encode("rfc7231")
on utcDatetime
and offsetDateTime
when used in a header.
Use @encode
to configure.
TypeSpec | Example payload |
|
|
duration
Default behavior:
- Encoded as
ISO8601
Use @encode
to configure.
TypeSpec | Example payload |
|
|