Interceptable

public protocol Interceptable

Provides pre-submission hook which allows a Restable to mutate the HTTPURLRequest. For example, adding a token in a header.

  • Intercepts a URLRequest and allows the handler to mutate it to its heart content

    In the following example we conform SomeRequest to be an Interceptable, such that SomeRequest will attach an authorization HTTP Header prior to the request being sent:

    struct SomeRequest: Gettable {...}
    extension SomeRequest: Interceptable {
        func intercept(request: URLRequest) -> URLRequest {
            var req = request
            req.setValue("Token I_AM_KING", forHTTPHeaderField: "Authorization")
            return req
        }
    }
    

    Declaration

    Swift

    func intercept(request: URLRequest) -> URLRequest

    Parameters

    request

    The intercepted URLRequest

    Return Value

    A (possibly) mutated version of the provided request