MockHTTPClient

open class MockHTTPClient

Mock http client handles mocks JSON requests.

Subspec: Utility/HTTPClient

mockHTTPClient.perform(jsonFileName: "Events") { (resposnse: Result<[Event]>) in
    // Handle response.
}

The MockHTTPClient can load and decode the contents of a JSON file into a swift network model. The JSON file needs to be within the project directory.

  • Data decoder used to decode the JSON files.

    Declaration

    Swift

    private static let decoder: DataDecoder
  • Containts the json file names as a key and the json string content as the value.

    Declaration

    Swift

    private lazy var jsonMockFiles: [String : String] { get set }
  • Performs a mock network request.

    Declaration

    Swift

    public func perform<T: Decodable>(jsonFileName: String, completion: @escaping (_ result: Result<T>) -> Void)

    Parameters

    jsonFileName

    File name of the json file.

    completion

    Network completion that describes how the data should be deserialized.

  • Loads the JSON files in the project directory.

    Declaration

    Swift

    static func loadMockFiles() -> [String : String]

    Return Value

    A dictionary of file names and file content.

  • Parses the path given into the file name.

    Declaration

    Swift

    private static func fileName(path: String) -> String

    Parameters

    path

    Path to file.

    Return Value

    String file name.