StubResponse
open class StubResponse
StubResponse is the base response to simulate URLResponses.
It defines the HTTP Status code, the Responder Header and Body.
It can also define a delay in seconds, simulating delayed server responses.
-
Base initializer. Keep all the default properties’ values.
Declaration
Swift
public init() -
Initializes the response with a given data for the body.
Declaration
Swift
public init(data: Data)Parameters
dataA Data object to be used as is in the body.
-
Initializes the response with a given JSON as the body data.
Declaration
Swift
public init(json: [String : Any])Parameters
jsonA Dictionary using JSON standards.
-
Initializes the response with a given UTF8 string as the body data.
Declaration
Swift
public init(string: String)Parameters
stringA String in UTF8 format.
-
Initializes the response with the content of a given file.
Declaration
Swift
public init(filename: String, ofType type: String, bundle: Bundle = .main)Parameters
filenameA String with the file name only, no extension.
typeA string with the file extension only.
bundleThe bundle where the file is localed. By default it’s
.main.
-
Returns the same response object with a new delay.
Declaration
Swift
open func withDelay(_ time: Double) -> SelfParameters
timeA Double representing the delay in seconds.
Return Value
The same response with a new delay.
-
Returns the same response object with a new body.
Declaration
Swift
open func withBody(_ data: Data?) -> SelfParameters
dataA Data as the new body.
Return Value
The same response with a new body.
-
Returns the same response object with a new status code.
Declaration
Swift
open func withStatusCode(_ code: Int) -> SelfParameters
codeA String as the new status code.
Return Value
The same response with a new status code.
-
Returns the same response object with a new headers.
Declaration
Swift
open func withHeaders(_ httpHeaders: [String : String]) -> SelfParameters
httpHeadersA Dictionary with the new headers.
Return Value
The same response with a header.
View on GitHub
StubResponse Class Reference