Search code examples
iosdjangodjango-rest-framework

Django REST Framework API call using iOS


I have built a simple Django application and exposed some API endpoints with Django REST Framework. I am using basic auth for now. I have tested on the command line and all works perfectly:

curl -H 'Accept: application/json; indent=4' -u myuser:mypass http://myapp.herokuapp.com/items/

I am handing the API to an iOS developer. What would be the correct parameters to call in the iOS application to properly authenticate and deliver the JSON data? I am really not familiar with iOS development so I am at a loss as to how to approach this.


Solution

  • Our IOS dev actually used a slightly different implementation, and I'm posting his code for completeness.

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setRequestMethod:@"GET"];
    [request addRequestHeader:@"Authorization" value:[NSString stringWithFornat:@"Basic %@",      [ASIHTTPRequest base64forData:[[NSString stringWithFormat:@"%@:%@",username,password] dataUsingEncoding:NSUTF8StringEncoding]]]];
    [request setDidFinishSelector:@selector(requestFinished:)];
    [request start];