15
15
*/
16
16
17
17
/**
18
- This file contains examples of the `Coder`, `Encoder` and `Decoder` API.
19
- All those examples should eventually be moved to documentation and/or tests.
18
+ This file contains examples of the `Coder`, `Encoder` and `Decoder` API.
19
+ All those examples should eventually be moved to documentation and/or tests.
20
20
For now they are here to make sure we do not accidentally break any public API during development.
21
21
*/
22
22
@@ -51,8 +51,8 @@ fileprivate enum Requests {
51
51
. encodeStaticMetadata ( " metrics " , using: RoutingEncoder ( ) )
52
52
. encodeData ( using: JSONDataEncoder ( type: Metrics . self) )
53
53
}
54
- /// Same as above but gives the call site the option to encode additional dynamic metadata
55
- static let metrics3 = FireAndForget< ( [ CompositeMetadata ] , Metrics) > {
54
+ /// Same as above but gives the call site the option to encode additional dynamic metadata
55
+ static let metrics3 = FireAndForget < ( ( ) , Metrics ) > {
56
56
Encoder ( )
57
57
. useCompositeMetadata ( )
58
58
. encodeStaticMetadata ( " metrics " , using: RoutingEncoder ( ) )
@@ -67,7 +67,6 @@ fileprivate enum Requests {
67
67
static let priceRequest1 = RequestResponse < String , Double > {
68
68
Encoder ( )
69
69
. useCompositeMetadata ( )
70
- . encodeStaticMetadata ( " price " , using: RoutingEncoder ( ) )
71
70
. encodeStaticMetadata ( [ . applicationJson] , using: AcceptableDataMIMETypeEncoder ( ) )
72
71
. encodeData ( using: JSONDataEncoder ( type: Stock . self) )
73
72
. mapData ( Stock . init ( isin: ) )
@@ -76,7 +75,7 @@ fileprivate enum Requests {
76
75
. decodeData ( using: JSONDataDecoder ( type: Price . self) )
77
76
. mapData ( \. price)
78
77
}
79
- /// Same as above but we do no longer need to explicitly encode the Acceptable Data MIME Type.
78
+ /// Same as above but we do no longer need to explicitly encode the Acceptable Data MIME Type.
80
79
/// This is because we use the `Coder` convenience API which is a thin wrapper around an `Encoder` and `Decoder`.
81
80
/// `Coder.decodeData(decoder:)` takes multiple decoders and automatically encodes their MIME Type as Acceptable Data MIME Type Metadata.
82
81
/// It also looks for Data MIME Type and the Connection MIME Type and choose the correct decoder during decoding.
@@ -85,23 +84,21 @@ fileprivate enum Requests {
85
84
. useCompositeMetadata ( )
86
85
. encodeStaticMetadata ( " price " , using: RoutingEncoder ( ) )
87
86
. encodeData ( using: JSONDataEncoder ( type: ISIN . self) . map ( ISIN . init ( isin: ) ) )
88
- . decodeData {
89
- JSONDataDecoder ( type: Price . self) . map ( \. price)
90
- }
87
+ . decodeData ( using: JSONDataDecoder ( type: Price . self) . map ( \. price) )
91
88
}
92
89
93
90
/// Same as above but this time the encoder also encodes the MIME Type of the data as Date MIME Type Metadata because we use the `encodeData(encoder:)` method which can take multiple encoders. The call side need to specify which encoding it wants to use.
94
- static let priceRequest3 = RequestResponse < ( MIMEType , String ) , Double > {
91
+ static let priceRequest3 = RequestResponse < ( String ) , Double > {
95
92
Coder ( )
96
93
. useCompositeMetadata ( )
97
94
. encodeStaticMetadata ( " price " , using: RoutingEncoder ( ) )
98
- . encodeData {
95
+ . encodeData ( using :
99
96
JSONDataEncoder ( type: ISIN . self) . map ( ISIN . init ( isin: ) )
100
- }
101
- . decodeData {
97
+ )
98
+ . decodeData ( using :
102
99
JSONDataDecoder ( type: Price . self)
103
100
. map ( \. price)
104
- }
101
+ )
105
102
}
106
103
/// Works with `RequestStream` and `RequestChannel` too
107
104
static let priceStream1 = RequestStream < ISIN , Price > {
0 commit comments