EndpointInterface

public protocol EndpointInterface

A protocol that defines the requirements for building and manipulating API endpoint URLs.

Conforming types must provide methods for adding versions, controllers, paths, and query parameters to endpoints, as well as building the final URL string. This protocol supports both string and enumerator-based inputs for flexibility and readability.

  • url

    The URL of the request.

    Declaration

    Swift

    var url: String { get }
  • Adds a version to the endpoint This can be added using the add(path: String) method but it’s better for readability NOTE: Do not append nor prepend the foward slash

    Declaration

    Swift

    @discardableResult
    func withVersion(_ version: String) -> Endpoint

    Parameters

    version

    The version of the endpoint as string

  • Adds a version to the endpoint This can be added using the add(path: String) method but it’s better for readability This method accepts a enumerator instead of a string

    Declaration

    Swift

    @discardableResult
    func withVersion<T>(_ version: T) -> Endpoint where T : StringRepresentable

    Parameters

    version

    The version of the endpoint as string

    T

    The type of the enumerator containing the version

  • Adds a controller to the endpoint This can be added using the withPath(_ path: String) method but it’s better for readability NOTE: Do not append nor prepend the foward slash

    Declaration

    Swift

    @discardableResult
    func withController(_ controller: String) -> Endpoint

    Parameters

    controller

    The controller of the endpoint, usually a controller contains muitiple endpoints

  • Adds a controller to the endpoint This can be added using the withPath(_ path: String) method but it’s better for readability

    Declaration

    Swift

    @discardableResult
    func withController<T>(_ controller: T) -> Endpoint where T : StringRepresentable

    Parameters

    controller

    The controller of the endpoint, usually a controller contains muitiple endpoints

    T

    The type of the enumerator containing the controller

  • Adds a path to the endpoint NOTE: Do not append nor prepend the foward slash

    Declaration

    Swift

    @discardableResult
    func withPath(_ path: String) -> Endpoint

    Parameters

    path

    The path to the endpoint

  • Adds a path to the endpoint The path can contain values like {id} where {id} will be replaced by the key in the dictionary parameters NOTE: Do not append nor prepend the foward slash

    Declaration

    Swift

    @discardableResult
    func withPath(_ path: String, parameters: [String : String]) -> Endpoint

    Parameters

    path

    The path to the endpoint

    parameters

    The dictionary with the parameters to replace

  • Adds query parameters to the url

    Declaration

    Swift

    @discardableResult
    func withQuery(_ query: [String : String]) -> Endpoint

    Parameters

    query

    The dictionary of query values to add

  • Builds the URL

    Throws

    SwiftlyRestError.invalidURL if the provided URL is not valid

    Declaration

    Swift

    func build() throws -> String

    Return Value

    The built URL