RequestBuilder

public class RequestBuilder : CustomStringConvertible, CustomDebugStringConvertible
extension RequestBuilder: URLRequestConvertible

A builder pattern to easily create http requests

Note: The base URL will be injected by the APIClient so only path if configured here.

  • Declaration

    Swift

    public var debugDescription: String { get }
  • Declaration

    Swift

    public var description: String { get }
  • Undocumented

    Declaration

    Swift

    public private(set) var baseURL: String? { get }
  • Enumeration of HTTP Verbs

    See more

    Declaration

    Swift

    public enum Method : String
  • A type representing the encoding to be used for request body

    See more

    Declaration

    Swift

    public enum Encoding
  • Undocumented

    Declaration

    Swift

    public typealias Headers = [String : String]
  • Undocumented

    Declaration

    Swift

    public typealias QueryParams = [String : Any]
  • Undocumented

    Declaration

    Swift

    public private(set) var headers: Headers? { get }
  • Undocumented

    Declaration

    Swift

    public private(set) var queryParameters: QueryParams? { get }

Factories

  • Creates a request builder for a POST request

    Declaration

    Swift

    public static func post(_ path: Path) -> RequestBuilder
  • Creates a request builder for a GET request

    Declaration

    Swift

    public static func get(_ path: Path) -> RequestBuilder
  • Creates a request builder for a PUT request

    Declaration

    Swift

    public static func put(_ path: Path) -> RequestBuilder
  • Creates a request builder for a PATCH request

    Declaration

    Swift

    public static func patch(_ path: Path) -> RequestBuilder

Builders

  • Sets the base url for the formed request Note: base url should not have a trailing / since this is added in paths.

    Declaration

    Swift

    public func baseURL(_ string: String) -> RequestBuilder
  • Adds body content from raw data.

    Declaration

    Swift

    public func body(_ body: Data) -> RequestBuilder
  • Adds a json payload to body given a codable value.

    Note this will also set the content-type to application/json

    Declaration

    Swift

    public func jsonBody<T>(_ payload: T) -> RequestBuilder where T : Encodable
  • Adds a json payload to body from a dictionary

    Note this will also set the content-type to application/json

    Declaration

    Swift

    public func jsonBody(dict: [String : Any]) -> RequestBuilder
  • Add a body payload encoded a form-url

    Note this will also set the content-type to application/x-www-form-urlencoded

    Declaration

    Swift

    public func formUrlBody(_ params: [String : String], encoding: Encoding) -> RequestBuilder
  • Adds header to request

    Declaration

    Swift

    public func addHeader(_ header: String, value: String) -> RequestBuilder
  • Adds multiple query paramater pairs to url

    Declaration

    Swift

    public func query(_ query: QueryParams) -> RequestBuilder
  • Adds multiple query paramater pairs to url

    Declaration

    Swift

    public func query(_ queryItems: [URLQueryItem]?) -> RequestBuilder
  • Adds a single query parameter to url

    Declaration

    Swift

    public func addQuery(_ query: String, value: String) -> RequestBuilder
  • Transforms the RequestBuilder into a URLRequest

    Declaration

    Swift

    public func asURLRequest(baseURL: URL?) -> URLRequest