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?) -> NetworkResourceWithBodyParameters
keyheader name
valueheader 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>) -> NetworkResourceWithBodyParameters
dictionaryDictionary of header key value pairs
Return Value
NetworkResourceWithBody
-
Adds the given credentials as a Basic HTTP Hidden Authorization Header into to the resource.
The
usernameandpasswordare base64 encoded before being set into theAuthorizationheader of request.Declaration
Swift
@discardableResult @objc override func authorizationHeader(username: String, password: String) -> NetworkResourceWithBodyParameters
userThe username
passwordThe 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>) -> NetworkResourceWithBodyParameters
dictionaryDictionary 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>) -> NetworkResourceWithBodyParameters
dictionaryDictionary 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?) -> NetworkResourceWithBodyParameters
datadata to be sent
mimeTypeMIME/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 = []) -> NetworkResourceWithBodyParameters
bodykey-value pairs
optionsJSONSerialization.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()) -> NetworkResourceWithBodyParameters
bodyA type conforming to the
EncodableProtocoloptionsThe
JSONEncoderinstance 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 = []) -> NetworkResourceWithBodyParameters
bodyArray
optionsJSONSerialization.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") -> NetworkResourceWithBodyParameters
dataData
nameString
mimeTypeString (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") -> NetworkResourceWithBodyParameters
dataData
nameString
fileNameString
mimeTypeString (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") -> NetworkResourceWithBodyParameters
withFileThe name (without extension) of the file containing the mocked response. The file must be present in the main bundle (
Bundle.main)ofTypeThe extension of the file. Defaults to
.jsonif not provided.Return Value
NetworkResourceWithBody
-
Sets whether the request should wait for Constraints or not.
falseby 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) -> NetworkResourceWithBodyParameters
contentTypeContent-Type
Return Value
NetworkResourceWithBody
View on GitHub
Install in Dash
NetworkResourceWithBody Class Reference