         
         
         
-            // Send the request to the API and parse
-            var urlToPackage = url.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
-            println(urlToPackage)
-            var urlToSend: NSURL = NSURL(string: urlToPackage!)!
-            var apiSessionConfiguration: NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
-            apiSessionConfiguration.timeoutIntervalForRequest = timeOut
-            var session = NSURLSession(configuration:apiSessionConfiguration)
-            var request = NSMutableURLRequest(URL:urlToSend)
-            request.addValue("application/json",forHTTPHeaderField:"Accept")
-            var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
-                println("Task completed")
-                if((error) != nil) {
-                    // if there is an error in the request, print it to the console
-                    self.delegate?.didCompleteWithError(error.localizedDescription)
-                    //println(error.localizedDescription)
-                    println("oops!")
-                }
-                var err: NSError?
-                if self.responseFormat == "JSON" {
-                    var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as! NSDictionary
+        // Send the request to the API and parse
+        var urlToPackage = url.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
+        println(urlToPackage)
+        var urlToSend: NSURL = NSURL(string: urlToPackage!)!
+        var apiSessionConfiguration: NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
+        apiSessionConfiguration.timeoutIntervalForRequest = timeOut
+        var session = NSURLSession(configuration: apiSessionConfiguration, delegate: self, delegateQueue:NSOperationQueue.mainQueue())
+        var request = NSMutableURLRequest(URL:urlToSend)
+        request.addValue("application/json",forHTTPHeaderField:"Accept")
+        if (APIHost == URL_API_V2) {
+            request.addValue(APIKey, forHTTPHeaderField: "X-API-KEY")
+        }
+        var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
+            println("Task completed")
+            if((error) != nil) {
+                // if there is an error in the request, print it to the console
+                self.delegate?.didCompleteWithError(error.localizedDescription)
+                //println(error.localizedDescription)
+                println("oops!")
+            }
+            var err: NSError?
+            if self.responseFormat == "JSON" {
+                if let jsonResult: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) {
                     if(err != nil) {
                         // If there is an error parson JSON, print it to the console
                         NSLog ("Error parsing the JSON")
                     }
-                    self.delegate?.didCompleteWithDictionary(jsonResult)
-                } else if self.responseFormat == "XML" {
-                    //let parser = SWXMLHash()
-                    var dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
-                    let xml = SWXMLHash.parse(data)
-                    self.delegate?.didCompleteWithXML(xml)
+                    if jsonResult is NSDictionary {
+                        self.delegate?.didCompleteWithDictionary(jsonResult as! NSDictionary)
+                    }
+                    else if jsonResult is NSArray {
+                        self.delegate?.didCompleteWithArray(jsonResult as! NSArray)
+                    }
+                    else {
+                        //return Object
+                        self.delegate?.didComplete(jsonResult as! NSString)
+                    }
                 }
-                })
-            task.resume()
+                
+            } else if self.responseFormat == "XML" {
+                //let parser = SWXMLHash()
+                var dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
+                let xml = SWXMLHash.parse(data)
+                self.delegate?.didCompleteWithXML(xml)
+            }
+        })
+        task.resume()
     }
-
-   
+    
+    func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) {
+        completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, NSURLCredential(forTrust: challenge.protectionSpace.serverTrust))
+    }
+    
+    
+    
 }
        //Construct the arguments part of the query string
        for (argKey, argValue) in arguments {
            switch APIHost {
            case "http://api.dol.gov":
                // DOL's V1 API has specific formatting requirements for arguments in the query string
                switch argKey {
                case "top", "skip", "select", "orderby", "filter":

        
        // Where appropriate, add the key
        switch APIHost {
        case URL_API_V1:
            queryString = "?KEY=" + APIKey
        case URL_API_V2:
            queryString = ""
        case "http://api.census.gov", "http://pillbox.nlm.nih.gov":
            queryString = "?key=" + APIKey
        case "http://api.eia.gov", "http://developer.nrel.gov", "http://api.stlouisfed.org", "http://healthfinder.gov":
