You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To generate request JSON, pass `RequestType` instances to `BatchFactory` instance, which has common JSON-RPC version and identifier generator.
62
+
To generate request JSON, pass `Request` instances to `BatchFactory` instance, which has common JSON-RPC version and identifier generator.
74
63
When `BatchFactory` instance receives request(s), it generates identifier(s) for the request(s) and request JSON by combining id, version, method and parameters.
75
64
76
65
```swift
77
66
let batchFactory =BatchFactory(version: "2.0", idGenerator: NumberIdGenerator())
78
-
let request1 =CountCharactersRequest(characters: "tokyo")
79
-
let request2 =CountCharactersRequest(characters: "california")
67
+
let request1 =Subtract(minuend: 42, subtrahend: 23)
68
+
let request2 =Subtract(minuend: 23, subtrahend: 42)
80
69
let batch = batchFactory.create(request1, request2)
81
70
```
82
71
@@ -85,20 +74,22 @@ The request JSON is available in `batch.requestObject`. It looks like below:
85
74
```json
86
75
[
87
76
{
77
+
"method" : "subtract",
88
78
"jsonrpc" : "2.0",
89
-
"method" : "count_characters",
90
79
"id" : 1,
91
-
"params" : {
92
-
"characters" : "tokyo"
93
-
}
80
+
"params" : [
81
+
42,
82
+
23
83
+
]
94
84
},
95
85
{
86
+
"method" : "subtract",
96
87
"jsonrpc" : "2.0",
97
-
"method" : "count_characters",
98
88
"id" : 2,
99
-
"params" : {
100
-
"characters" : "california"
101
-
}
89
+
"params" : [
90
+
23,
91
+
42
92
+
]
102
93
}
103
94
]
104
95
```
@@ -111,31 +102,29 @@ Suppose that following JSON is returned from server:
111
102
```json
112
103
[
113
104
{
105
+
"result" : 19,
114
106
"jsonrpc" : "2.0",
115
107
"id" : 1,
116
-
"result" : {
117
-
"count" : 5
118
-
}
108
+
"status" : 0
119
109
},
120
110
{
111
+
"result" : -19,
121
112
"jsonrpc" : "2.0",
122
113
"id" : 2,
123
-
"result" : {
124
-
"count" : 10
125
-
}
114
+
"status" : 0
126
115
}
127
116
]
128
117
```
129
118
130
-
To parse response object, execute `responsesFromObject(_:)` of `BatchType` instance.
131
-
When `responsesFromObject(_:)` is called, `BatchType` finds corresponding response object by comparing request id and response id.
132
-
After it find the response object, it executes `responsesFromObject(_:)` of `Response` to get `Request.Response` from the response object.
119
+
To parse response object, execute `responses(from:)` of `Batch` instance.
120
+
When `responses(from:)` is called, `Batch` finds corresponding response object by comparing request id and response id.
121
+
After it find the response object, it executes `responses(from:)` of `Response` to get `Request.Response` from the response object.
133
122
134
123
```swift
135
124
let responseObject =...
136
-
let (response1, response2) =try! batch.responsesFromObject(responseObject)
0 commit comments