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.
-
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 slashDeclaration
Swift
@discardableResult func withVersion(_ version: String) -> EndpointParameters
versionThe 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 stringDeclaration
Swift
@discardableResult func withVersion<T>(_ version: T) -> Endpoint where T : StringRepresentableParameters
versionThe version of the endpoint as string
TThe 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 slashDeclaration
Swift
@discardableResult func withController(_ controller: String) -> EndpointParameters
controllerThe 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 readabilityDeclaration
Swift
@discardableResult func withController<T>(_ controller: T) -> Endpoint where T : StringRepresentableParameters
controllerThe controller of the endpoint, usually a controller contains muitiple endpoints
TThe 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) -> EndpointParameters
pathThe 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 dictionaryparametersNOTE: Do not append nor prepend the foward slashDeclaration
Swift
@discardableResult func withPath(_ path: String, parameters: [String : String]) -> EndpointParameters
pathThe path to the endpoint
parametersThe dictionary with the parameters to replace
-
Adds query parameters to the url
Declaration
Swift
@discardableResult func withQuery(_ query: [String : String]) -> EndpointParameters
queryThe dictionary of query values to add
-
Builds the URL
Throws
SwiftlyRestError.invalidURLif the provided URL is not validDeclaration
Swift
func build() throws -> StringReturn Value
The built URL