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

    data

    A 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

    json

    A Dictionary using JSON standards.

  • Initializes the response with a given UTF8 string as the body data.

    Declaration

    Swift

    public init(string: String)

    Parameters

    string

    A 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

    filename

    A String with the file name only, no extension.

    type

    A string with the file extension only.

    bundle

    The 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) -> Self

    Parameters

    time

    A 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?) -> Self

    Parameters

    data

    A 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) -> Self

    Parameters

    code

    A 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]) -> Self

    Parameters

    httpHeaders

    A Dictionary with the new headers.

    Return Value

    The same response with a header.