Created
April 14, 2015 07:38
-
-
Save astannard/6d17552d83c83b9e4d56 to your computer and use it in GitHub Desktop.
iOS Swift Post Request Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = NSMutableURLRequest(URL: NSURL(string: "https://api.nutritionix.com/v1_1/search/")!) | |
let session = NSURLSession.sharedSession() | |
request.HTTPMethod = "POST" | |
var params = [ | |
"appId" : kAppId, | |
"appKey" : kAppKey, | |
"fields" : ["item_name", "brand_name", "keywords", "usda_fields"], | |
"limit" : "50", | |
"query" : searchString, | |
"filters": ["exists":["usda_fields": true]] | |
] | |
var error: NSError? | |
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &error) | |
request.addValue("application/json", forHTTPHeaderField: "Content-Type") | |
request.addValue("application/json", forHTTPHeaderField: "Accept") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment