title: How do I perform GET and POST requests in Swift?
body: <p>I adapted this from Ray Wenderlich's iOS Apprentice tutorial part 4.</p>
  
  <p>This code works as a GET request sent to my Strongloop API with a simple database model, however:</p>
  
  <ol>
  <li><p>This works, but I don't know why it works, since it invokes no method that I can see to actually send the request.</p></li>
  <li><p>I see no means to make it into a POST request.</p></li>
  </ol>
  
  <p>My question is: How do I perform a POST request? Is it done in a completely different way?</p>
  
  <p>Let me know if you need more information.</p>
  
  <pre><code>    class ViewController: UIViewController {
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      @IBAction func getFromDB() {
          let url = urlWithSearchText("")
          println("URL: '\(url)'")
          if let jsonString = performGetRequestWithURL(url) {
              println("Received JSON string '\(jsonString)'")
          }
      }
  
  
      func urlWithSearchText(searchText: String) -&gt; NSURL {
          let escapedSearchText = searchText.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
          let urlString = String(format: "http://localhost:3000/api/Tests", escapedSearchText)
          let url = NSURL(string: urlString)
          return url!
      }    
  
      func performGetRequestWithURL(url: NSURL) -&gt; String? {
          var error: NSError?
          if let resultString = String(contentsOfURL: url, encoding: NSUTF8StringEncoding, error: &amp;error) {
              return resultString
          } else if let error = error {
              println("Download Error: \(error)")
          } else {
              println("Unknown Download Error")
          }
          return nil
      }
  </code></pre>
  
  <p>Here is a picture of this working:</p>
  
  <p><a href="https://dl.dropboxusercontent.com/u/14464971/Images/Messages%20Image%281477993527%29.png" rel="noreferrer">https://dl.dropboxusercontent.com/u/14464971/Images/Messages%20Image%281477993527%29.png</a></p>