API Tools

Low level classes to simplify implementing REST API calls via URLRequest and URLSession. Feel free to use them if you wish.

  • Convenience protocol to define connection parameters for API calls when using URLRequest via JcConnectionRequest

    See more

    Declaration

    Swift

    public protocol JcConnection
  • Represents credentials to be used for making requests

    Declaration

    Swift

    public class JcCredentials
  • Convenience class to simplify API calls via wrapped instances of UrlRequest and UrlSession You will need instantiate a valid JcConnection object via the JcConnectionFactory class to instantiate an object of this class.

    Notes:

    This class should not be used directly, use it as a inherited class and leverage the various _get(resourcePath:completionHandler:), _delete(resourcePath:completionHandler:) _execute(method:resourcePath:contentType:request:completionHandler:) methods from your class.

    Objects derived from this class are not thread safe and should be reused. Create an instance for each request as required

    See more

    Declaration

    Swift

    public class JcConnectionRequest<T> where T : JcSimpleConnection
  • Undocumented

    Declaration

    Swift

    public protocol JcEncodableContent : Decodable, Encodable
  • Convenience class to allow multi-part formatted data to be sent/received via http/s

    Example: (get)

    return super._getMultipart(resourcePath: args(id)) { (response) in
    
       if (response.status == .SUCCESS) {
    
           for part in response.content!.parts {
               var name = part.name
               var filename = part.fileName
               var contentType = part.contentType
    
               var data = part.content
           }
       }
    }
    

    Example: (post)

    var mp = JcMultiPartContent()
    mp.add("object", contentType: nil, content: Data("{\"name\": \"\(name)\", \"type\":\"\(contentType)\"}".utf8))
    mp.add("filesize", contentType: nil, content: Data("\(data.count)".utf8))
    mp.add("file", contentType: contentType, content: data)
    
    return super._execute(method: JcConnectionRequest.Method.POST, resourcePath: C8Y_BINARIES_API, request: mp) { (response) in
    
       if (response.status == .SUCCESS) {
           ...
       }
    }
    
    See more

    Declaration

    Swift

    public struct JcMultiPartContent