HTTPEngine
public struct HTTPEngine
Undocumented
-
Undocumented
Declaration
Swift
public init() -
Creates a URLRequest Object
– Headers
By default all requests have the
["Accept-Encoding": "gzip;q=1.0,compress;q=0.5"]header included.All
.post, .put, & .patchrequests also contain["Content-Type": "application/json"]by default.These values can be overridden by including those headers as arguments when calling this function
Declaration
Swift
public func buildRequest( method: HTTPMethod, url: URL, body: Data? = nil, header: Header? = nil ) -> URLRequestParameters
methodHTTPMethod -
.get, .put. postetc.,urlA URL Object
bodyData?: The body data to send with a request
headerA dictionary of HTTP Request Headers -
["Content-Type": "text", "Some Key": "Some Value"]Return Value
A fully constructed URLRequest
-
Makes a request via HTTP
– Headers
By default all requests have the
["Accept-Encoding": "gzip;q=1.0,compress;q=0.5"]header included.All
.post, .put, & .patchrequests also contain["Content-Type": "application/json"]by default.These values can be overridden by including those headers as arguments when calling this function
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
public func makeRequest( method: HTTPMethod, url urlString: String, body: Data? = nil, header: Header? = nil, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Data, Error>Parameters
methodHTTPMethod -
.get, .put. postetc.,urlStringURL domain + path as a string:
"abc.com/some/path"bodyData?: The body data to send with a request
headerA dictionary of HTTP Request Headers -
["Content-Type": "text", "Some Key": "Some Value"]validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a request via HTTP and Decodes the response
– Headers
By default all requests have the
["Accept-Encoding": "gzip;q=1.0,compress;q=0.5"]header included.All
.post, .put, & .patchrequests also contain["Content-Type": "application/json"]by default.These values can be overridden by including those headers as arguments when calling this function
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func makeRequestAndParseResponse<Response: Decodable>( _ decodableResponse: Response.Type, method: HTTPMethod, url: String, header: Header? = nil, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
methodHTTPMethod -
.get, .put. postetc.,urlStringURL domain + path as a string:
"abc.com/some/path"headerA dictionary of HTTP Request Headers -
["Content-Type": "text", "Some Key": "Some Value"]validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a request via HTTP, Encodes the body and Decodes the response
– Headers
By default all requests have the
["Accept-Encoding": "gzip;q=1.0,compress;q=0.5"]header included.All
.post, .put, & .patchrequests also contain["Content-Type": "application/json"]by default.These values can be overridden by including those headers as arguments when calling this function
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func makeRequestAndParseResponse<Body: Encodable, Response: Decodable>( _ decodableResponse: Response.Type, method: HTTPMethod, url: String, body: Body?, header: Header? = nil, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
methodHTTPMethod -
.get, .put. postetc.,urlStringURL domain + path as a string:
"abc.com/some/path"bodyEncodable?: The encodable object that represents body data to send with a request
headerA dictionary of HTTP Request Headers -
["Content-Type": "text", "Some Key": "Some Value"]validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a request via HTTP and Decodes the response
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func get<Response: Decodable>( _ value: Response.Type, url: String, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
urlStringURL domain + path as a string:
"abc.com/some/path"validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a POST request via HTTP, Encodes the body and Decodes the response
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func post<Response: Decodable, Body: Encodable>( _ value: Response.Type, url: String, body: Body? = nil, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
urlStringURL domain + path as a string:
"abc.com/some/path"bodyEncodable?: The encodable object that represents body data to send with a request
validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a POST request via HTTP, Encodes the body and Decodes the response
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func post<Response: Decodable>( _ value: Response.Type, url: String, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
urlStringURL domain + path as a string:
"abc.com/some/path"validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a PATCH request via HTTP, Encodes the body and Decodes the response
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func patch<Response: Decodable, Body: Encodable>( _ value: Response.Type, url: String, body: Body? = nil, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
urlStringURL domain + path as a string:
"abc.com/some/path"bodyEncodable?: The encodable object that represents body data to send with a request
validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a PUT request via HTTP, Encodes the body and Decodes the response
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func put<Response: Decodable, Body: Encodable>( _ value: Response.Type, url: String, body: Body? = nil, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
urlStringURL domain + path as a string:
"abc.com/some/path"bodyEncodable?: The encodable object that represents body data to send with a request
validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
-
Makes a DELETE request via HTTP, Encodes the body and Decodes the response
– Validation
By default the validation checks for a 200-299 status code and fails if the code is out of bounds
// example validator validator: { $0 == 202 } // Failure throws Errors.Response.unexpectedStatusCode(HTTPURLRequest)Declaration
Swift
func delete<Response: Decodable, Body: Encodable>( _ value: Response.Type, url: String, body: Body? = nil, validator: ResponseValidationClosure? = nil ) -> AnyPublisher<Response, Error>Parameters
decodableResponseDecodable - An object that represents the response body
urlStringURL domain + path as a string:
"abc.com/some/path"bodyEncodable?: The encodable object that represents body data to send with a request
validator(Int) -> Bool- A function to validate the response code of the request. By default, makeRequest() will fail if the status code does not fall within the 200 - 299 range. To override this, pass in a function that compares the status code and returns a boolean. True == success, False == failure. Upon failure an error will be thrown that contains the HTTPURLResponse for inspection.Return Value
AnyPubliser
HTTPEngine Structure Reference