Skip to content

Commit

Permalink
Add URLSessionConfiguration to Fetch.Config (#22)
Browse files Browse the repository at this point in the history
* add URLSessionConfiguration to Fetch Config
* added documentation

Co-authored-by: Stefan Haider <stefan.haider@post.at>
  • Loading branch information
stfnhdr and Stefan Haider authored Aug 24, 2021
1 parent ce5ea3e commit 86e958f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Fetch/Code/Network/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public struct Config {
public var baseURL: URL
public var defaultHeaders: HTTPHeaders
public var timeout: TimeInterval
public var urlSession: URLSessionConfiguration
public var eventMonitors: [EventMonitor]
public var interceptor: RequestInterceptor?
public var decoder: ResourceDecoderProtocol
Expand All @@ -30,6 +31,7 @@ public struct Config {
/// - baseURL: The base `URL` used for all request, if not specified by the `Resource`
/// - defaultHeaders: The `HTTPHeaders` used for all request, if not specified by the `Resource`
/// - timeout: The request timeout interval controls how long (in seconds) a task should wait for additional data to arrive before giving up
/// - urlSession: The `URLSessionConfiguration` passed to the Alamofire `Session`
/// - eventMonitors: The `EventMonitor` array passed to the Alamofire `Session`
/// - adapter: The `RequestAdapter` passed to the Alamofire `Session`
/// - retrier: The `RequestRetrier` passed to the Alamofire `Session`
Expand All @@ -42,6 +44,7 @@ public struct Config {
public init(baseURL: URL,
defaultHeaders: HTTPHeaders = HTTPHeaders.default,
timeout: TimeInterval = 60 * 2,
urlSession: URLSessionConfiguration = URLSessionConfiguration.default,
eventMonitors: [EventMonitor] = [APILogger(verbose: true)],
interceptor: RequestInterceptor? = nil,
jsonDecoder: ResourceDecoderProtocol = JSONDecoder(),
Expand All @@ -53,6 +56,7 @@ public struct Config {
self.baseURL = baseURL
self.defaultHeaders = defaultHeaders
self.timeout = timeout
self.urlSession = urlSession
self.eventMonitors = eventMonitors
self.interceptor = interceptor
self.decoder = jsonDecoder
Expand Down Expand Up @@ -116,7 +120,7 @@ public class APIClient {
public func setup(with config: Config) {
self._config = config

let configuration = URLSessionConfiguration.default
let configuration = config.urlSession
configuration.protocolClasses = config.protocolClasses + [StubbedURL.self]
configuration.timeoutIntervalForRequest = config.timeout

Expand Down

0 comments on commit 86e958f

Please sign in to comment.