APIEndpoint

public struct APIEndpoint

Helper object that centralize all required parameters for an endpoint

  • root URL. I.e. github.com, developer.apple.com and so forth. Ending slash (/) is not required; in case a path is provided it’ll be automatically added for those cases.

    Declaration

    Swift

    public let host: String
  • HTTP method for this endpoint

    Declaration

    Swift

    public let httpMethod: HTTPMethod
  • endpoint http scheme that defines what kind of connection is

    Declaration

    Swift

    public let scheme: APIScheme
  • timeout before the request expires

    Declaration

    Swift

    public let timeout: TimeInterval
  • Creates an APIEndpoint with the set of given values

    Declaration

    Swift

    public init(host: String,
                httpMethod: HTTPMethod = .get,
                scheme: APIScheme = .safe,
                timeout: TimeInterval = 10)

    Parameters

    host

    root URL. I.e. github.com, developer.apple.com and so forth. Ending slash (/) is not required; in case a path is provided it’ll be automatically added for those cases.

    httpMethod

    type of HTTP method this endpoint will handle. Defaults to .get type

    scheme

    whether or not this is a safe connection. Defaults to .safe type (https)

    timeout

    timeout before the request expires. Defaults to 10 seconds

  • Builds a complete URL from the host value, given a path

    Example of usage:

     let githubEndpoint = APIEndpoint(host: "github.com")
     githubEndpoint.buildRequest(for: "events")
     // returns -> https://github.com/events
    

    Declaration

    Swift

    public func buildRequest(for path: String, with queryDictionary: [String : String] = [:]) -> URLBuilderResult

    Parameters

    path

    path (with or without query parameters) to append to the existing host

    queryDictionary

    param query in the form of a dictionary to be assembled into the resulting URLRequest. Defaults to an empty one

    Return Value

    The assembled URL.