@@ -114,6 +114,7 @@ public final class RESTClient: Sendable {
114114 let baseQueryItems : [ URLQueryItem ]
115115 let jsonEncoder : JSONEncoder
116116 let jsonDecoder : JSONDecoder
117+ let urlSession : URLSession
117118 let requestPlugins : [ any RequestPlugin ]
118119 let responsePlugins : [ any ResponsePlugin ]
119120 let baseErrorContext : String ?
@@ -126,6 +127,7 @@ public final class RESTClient: Sendable {
126127 baseQueryItems: [ URLQueryItem ] = [ ] ,
127128 jsonEncoder: JSONEncoder = . init( ) ,
128129 jsonDecoder: JSONDecoder = . init( ) ,
130+ urlSession: URLSession = . shared,
129131 requestPlugins: [ any RequestPlugin ] = [ ] ,
130132 responsePlugins: [ any ResponsePlugin ] = [ ] ,
131133 baseErrorContext: String ? = nil ,
@@ -136,6 +138,7 @@ public final class RESTClient: Sendable {
136138 self . baseQueryItems = baseQueryItems
137139 self . jsonEncoder = jsonEncoder
138140 self . jsonDecoder = jsonDecoder
141+ self . urlSession = urlSession
139142 self . requestPlugins = requestPlugins
140143 self . responsePlugins = responsePlugins
141144 self . baseErrorContext = baseErrorContext
@@ -221,7 +224,7 @@ public final class RESTClient: Sendable {
221224 let data : Data
222225 let response : URLResponse
223226 do {
224- ( data, response) = try await URLSession . shared . data ( for: request)
227+ ( data, response) = try await self . urlSession . data ( for: request)
225228 } catch {
226229 throw APIError . failedToLoadData ( error, self . errorContext ( requestContext: errorContext) )
227230 }
0 commit comments