Classes
The following classes are available globally.
-
An
See moreHTTPClient
that usesAlamofire
for sending requests.Declaration
Swift
public class AlamofireClient : HTTPClient
-
RestingClient
is the core class ofRestingKit
. It allows sending requests and receiving their responses as promises through a high-level API.The
RestingClient
is configured with the following components:baseUrl
: The base URL of the server we want to connect. One client can only connect to a single base URL. Therefore, if you wish to use multiple APIs, you should use different clients for each of them.decoder
: The decoder to use for decoding responses.requestConverter
: The converter to use for convertingRestingRequest
s toHTTPRequest
s.interceptors
: The interceptors to run for each request and response.httpClient
: The client responsible for sending the request and receiving its response.
There are two function families within the class:
perform(_:)
andupload(_:)
, each with several overloads for convenience. Even though they do the same thing in the core, The way to achieve their goal is different.perform(_:)
sends the request by loading the request body into memory, whileupload(_:)
streams the body from a file without loading it.upload(_:)
also allows tracking upload progress. For most requestsperform(_:)
should be good enough, but for cases when the request body is expected to be large,upload(_:)
should be preferred.The process within a
RestingClient
is the following:- The request converter converts the
RestingRequest
into anHTTPRequest
. - The interceptors are run with the produced
HTTPRequest
in the order provided. At this point, one of the interceptors might decide to modify the request or stop the execution chain by returning a response or and error. - If the interceptors doesn’t block the chain, the
HTTPClient
is called to perform the actual request. - The response from
HTTPClient
is passed to the interceptors. At this point, an interceptor might decide to change the response or recover from an error. - The response is then converted into an
HTTPResponse
by decoding the response body.
Cases when request promises might fail:
- The encoding of the request has failed.
- The decoding of the response has faied.
- Networking errors.
- The response status was not 2xx.
- An interceptor decided to raise an error.
Declaration
Swift
open class RestingClient
-
An interceptor that logs requests and responses, including errors if present.
See moreDeclaration
Swift
open class RequestResponseLoggingInterceptor : RestingInterceptor
-
A default implementation of
See moreHeaderProvider
supporting dynamic header provisioning.Declaration
Swift
public class RestingHeaderProvider : HeaderProvider
-
A default implementation of
See moreHeaderProvider
supporting dynamic variable provisioning.Declaration
Swift
public class RestingPathVariableProvider : PathVariableProvider
-
Represents a high-level HTTP Request.
See moreDeclaration
Swift
open class RestingRequest<RequestType, ResponseType>
Parameters
RequestType
The type of the request parameters.
ResponseType
The type of response.
-
x A
RequestConverter
that supports:- Path templating using GRMustache.swift
- Streamed requests
Declaration
Swift
public class RestingRequestConverter : RequestConverter
-
Represents a lower-level HTTP Response.
See moreDeclaration
Swift
public class HTTPDataResponse
-
An error thrown when a response status code is not 2xx.
See moreDeclaration
Swift
public class HTTPError : Error
-
Represents a higher-level HTTP Response.
See moreDeclaration
Swift
public class HTTPResponse<BodyType> : HTTPResponseType
-
An object that encodes
See moreEncodable
objects intoMultipartFormData
.Declaration
Swift
public class MultipartFormDataEncoder
-
An object that encodes
See moreEncodable
objects into an array ofURLQueryItem
.Declaration
Swift
public class QueryParameterEncoder
-
Represents a file to be sent through a multipart/form-data request.
Warning
Even tough the class isEncodable
, it is supposed to be encoded withMultipartFormDataEncoder
. Encoding with a different encoder will result in an undefined result.Declaration
Swift
public class MultipartFile : Encodable
-
A wrapper around PromiseKit’s Promise class that supports progress callbacks.
See moreDeclaration
Swift
public class ProgressablePromise<T> : AnyProgressablePromise