URLSession

internal extension URLSession
  • A generic method that decodes the response of a URLSessionTask

    Declaration

    Swift

    fileprivate func codableTask<T: Codable>(with url: URL,
                                                completionHandler: @escaping (T?, URLResponse?, Error?) -> Void) -> URLSessionDataTask

    Parameters

    url

    The URL for the REST service to be requested

    completionHandler

    A completion handler to decode the response

  • A convenience method that builds a URLSessionTask to search for movies on themoviedb.org

    Declaration

    Swift

    func searchMoviesResponseTask(with url: URL,
                                  completionHandler: @escaping (SearchMoviesResponse?, URLResponse?, Error?) -> Void) -> URLSessionDataTask

    Parameters

    url

    The URL for the REST service to be requested

    completionHandler

    A completion handler to decode the response

  • A convenience method that builds a URLSessionTask to download movie posters from themoviedb.org

    Declaration

    Swift

    func getMoviePosterTask(with url: URL,
    							  completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask

    Parameters

    url

    The URL for the REST service to be requested

    completionHandler

    A completion handler to handle the movie poster image

Helper Functions for Creating JSON Decoder

  • A convenience method to create a configured JSONDecoder for use with Decodable entities

    Declaration

    Swift

    func newJSONDecoder() -> JSONDecoder