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
APIEndpointwith the set of given valuesDeclaration
Swift
public init(host: String, httpMethod: HTTPMethod = .get, scheme: APIScheme = .safe, timeout: TimeInterval = 10)Parameters
hostroot 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.httpMethodtype of HTTP method this endpoint will handle. Defaults to
.gettypeschemewhether or not this is a safe connection. Defaults to
.safetype (https)timeouttimeout before the request expires. Defaults to
10seconds -
Builds a complete URL from the
hostvalue, given a pathExample of usage:
let githubEndpoint = APIEndpoint(host: "github.com") githubEndpoint.buildRequest(for: "events") // returns -> https://github.com/eventsDeclaration
Swift
public func buildRequest(for path: String, with queryDictionary: [String : String] = [:]) -> URLBuilderResultParameters
pathpath (with or without query parameters) to append to the existing host
queryDictionaryparam query in the form of a dictionary to be assembled into the resulting URLRequest. Defaults to an empty one
Return Value
The assembled URL.
View on GitHub
APIEndpoint Structure Reference