I write a code that get recipes in form of JSON from a server and present it into a UItable.
NSURL *url = [NSURL URLWithString:@"http://domain.com/recipes"];
[config setHTTPAdditionalHeaders:@{@"Authorization":@" Token token=\"3f71235466468b7f7\""}];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:nil delegateQueue:[NSOperationQueue mainQueue]];
[[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
recipes= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
[self.tableView reloadData];
}
] resume];
This server is written in Ruby. Now I want to write a request to delete a recipe. Here it is the instruction of my server . It said that I should use following curl to delete a recipes:
Delete recipes DELETE: /recipes/:id In Curl it would be something like that:
curl -H 'Authorization: Token token="0b774d575632b"' -X DELETE http://domain.com/recipes/22
I would like to implement the delete method. Infact, I knew that I need to implement following method.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//how to delete it from server??????
// Remove the row from data model
[recipes removeObjectAtIndex:indexPath.row];
// Request table view to reload
[tableView reloadData];
}
Does anybody know how can I implement delete method?