NetworkResourceWithBody
public class NetworkResourceWithBody : NetworkResource
A subclass of NetworkResource, with support for carrying a request body.
-
Adds the given header to the resource, or updates it’s value if it already exists.
Declaration
Swift
@discardableResult @objc override func header(key: String, value: String?) -> NetworkResourceWithBody
Parameters
key
header name
value
header value
Return Value
NetworkResourceWithBody
-
Adds the given headers to the resource, and updates the value of the ones that already exist.
Declaration
Swift
@discardableResult @objc override func headers(_ dictionary: Dictionary<String, String>) -> NetworkResourceWithBody
Parameters
dictionary
Dictionary of header key value pairs
Return Value
NetworkResourceWithBody
-
Adds the given credentials as a Basic HTTP Hidden Authorization Header into to the resource.
The
username
andpassword
are base64 encoded before being set into theAuthorization
header of request.Declaration
Swift
@discardableResult @objc override func authorizationHeader(username: String, password: String) -> NetworkResourceWithBody
Parameters
user
The username
password
The password
Return Value
NetworkResourceWithBody
-
Encodes the given dictionary into URL Allowed query parameters and adds them to the resource’s URL
Declaration
Swift
@discardableResult @objc override func query(_ dictionary: Dictionary<String, Any>) -> NetworkResourceWithBody
Parameters
dictionary
Dictionary containing the query parameters
Return Value
NetworkResourceWithBody
-
Sets the HTTP Body of the resource with form encoded data
Internally sets the Content-Type header of the resource to
application/x-www-form-urlencoded
Declaration
Swift
@discardableResult @objc func fields(_ dictionary: Dictionary<String, Any>) -> NetworkResourceWithBody
Parameters
dictionary
Dictionary containing key value pairs
Return Value
NetworkResourceWithBody
-
Sets the HTTP Body of the resource to the given Data
Declaration
Swift
@discardableResult @objc func data(_ data: Data, mimeType: String?) -> NetworkResourceWithBody
Parameters
data
data to be sent
mimeType
MIME/Content-Type to be set in the resource’s headers
Return Value
NetworkResourceWithBody
-
Sets the HTTP Body as JSON
Internally sets the Content-Type header of the resource to
application/json
Declaration
Swift
@discardableResult @objc func json(body: Dictionary<AnyHashable, Any>, options: JSONSerialization.WritingOptions = []) -> NetworkResourceWithBody
Parameters
body
key-value pairs
options
JSONSerialization.WritingOptions, empty [] by default.
Return Value
NetworkResourceWithBody
-
Sets the HTTP Body as JSON encoded from a type conforming to the
Encodable (Codable)
protocolInternally sets the Content-Type header of the resource to
application/json
Declaration
Swift
@discardableResult func json<T: Encodable>(encodable: T, encoder: JSONEncoder = JSONEncoder()) -> NetworkResourceWithBody
Parameters
body
A type conforming to the
Encodable
Protocoloptions
The
JSONEncoder
instance to use. Defaults toJSONEncoder()
Return Value
NetworkResourceWithBody
-
Sets the HTTP Body as JSON Array
Internally sets the Content-Type header of the resource to
application/json
Declaration
Swift
@discardableResult @objc func jsonArray(array: Array<Any>, options: JSONSerialization.WritingOptions = []) -> NetworkResourceWithBody
Parameters
body
Array
options
JSONSerialization.WritingOptions, empty [] by default.
Return Value
NetworkResourceWithBody
-
Sets the HTTP Body as Multipart Form Data
Any number of the multipart methods can be chained continuously, the form data will be encoded with the required boundaries when
.load()
is called.Declaration
Swift
@discardableResult @objc func multipart(data: Data, withName name: String, mimeType: String? = "application/octet-stream") -> NetworkResourceWithBody
Parameters
data
Data
name
String
mimeType
String (Defaults to application/octet-stream)
Return Value
NetworkResourceWithBody
-
Sets the HTTP Body as Multipart Form Data
Any number of the multipart methods can be chained continuously, the form data will be encoded with the required boundaries when
.load()
is called.Declaration
Swift
@discardableResult @objc func multipart(data: Data, withName name: String, fileName: String, mimeType: String? = "application/octet-stream") -> NetworkResourceWithBody
Parameters
data
Data
name
String
fileName
String
mimeType
String (Defaults to application/octet-stream)
Return Value
NetworkResourceWithBody
-
Mocks the response of the resource with the contents of the given filename. Note that if a request is mocked, it’ll never hit the network, and will NOT pass the Request Interceptors. It will, however, pass through the Response Intereptors.
Declaration
Swift
@discardableResult @objc override func mock(withFile: String, ofType: String = "json") -> NetworkResourceWithBody
Parameters
withFile
The name (without extension) of the file containing the mocked response. The file must be present in the main bundle (
Bundle.main
)ofType
The extension of the file. Defaults to
.json
if not provided.Return Value
NetworkResourceWithBody
-
Sets whether the request should wait for Constraints or not.
false
by default.If false, this request will not call any of the given Constraint’s methods, and will directly go the the Request Interceptors.
Declaration
Swift
@discardableResult @objc override func canHaveConstraints(_ flag: Bool) -> NetworkResourceWithBody
-
Adds the given tag to the resource
Declaration
Swift
@discardableResult @objc override func tag(_ tag: String) -> NetworkResourceWithBody
-
Adds the given tags to the resource
Declaration
Swift
@discardableResult @objc override func tags(_ tags: [String]) -> NetworkResourceWithBody
-
Sets the Queue on which the response should be delivered on. By default, every response is delivered on the main queue.
Declaration
Swift
@discardableResult @objc override func deliverOn(thread: DispatchQueue) -> NetworkResourceWithBody
-
Sets the Content-Type header of the resource.
Declaration
Swift
@discardableResult @objc override func contentType(_ contentType: String) -> NetworkResourceWithBody
Parameters
contentType
Content-Type
Return Value
NetworkResourceWithBody