Encoding of types
This document describe how the http library interpret TypeSpec built-in types and how to configure
Default behavior:
- bytesare serialized as- base64when used in any context that requires they be encoded to a string (such as in a model property that is serialized as JSON, or if transmitted as a string in a- "text/plain"payload).
- In the context of a binary payload ("application/octet-stream") or an HTTP File,bytesare not encoded. They represent the body of the request, response, or multipart field or the file’s exact contents.
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-streamop upload(@body data: bytes): void; // Accept application/octet-streamutcDatetime and offsetDateTime
Section titled “utcDatetime and offsetDateTime”Default behavior:
- Encoded as rfc7231when used in a header
- Encoded as rfc3339otherwise.
Use @encode to configure.
| TypeSpec | Example payload | 
|  |  | 
duration
Section titled “duration”Default behavior:
- Encoded as ISO8601
Use @encode to configure.
| TypeSpec | Example payload | 
|  |  | 
Numeric types ( int64, decimal128, float64, etc.)
Section titled “Numeric types ( int64, decimal128, float64, etc.)”By default numeric types are serialized as a JSON number. However for large types like int64 or decimal128 that cannot be represented in certain languages like JavaScript it is recommended to serialize them as string over the wire.
| TypeSpec | Example payload | 
|  |  |