Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: Best way to access REST API on your iphone

been wrestling with this for some time. I am trying to access a REST api on my iphone and came across the ASIHTTP framework that would assist me. So i did something like

//call sites, so we can confirm username and password and site/sites NSURL *url = [NSURL URLWithString: urlbase]; ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; [request setUsername:@"doronkatz%40xx.com" ]; [request setPassword:@"xxx"]; 

Where urlbase is a url to a REST site.

Now, a developer has told me there might be an issue or bug with this framework, and its not passing headers correctly. Is there another way of testing or accessing with authentication a network REST location?

like image 648
Doz Avatar asked Oct 12 '09 21:10

Doz


People also ask

How do I access REST API?

Step #1 – Enter the URL of the API in the textbox of the tool. Step #2 – Select the HTTP method used for this API (GET, POST, PATCH, etc). Step #3 – Enter any headers if they are required in the Headers textbox. Step #4 – Pass the request body of the API in a key-value pair.

What is REST API in IOS?

REST APIs or RESTful web services in layman's terms are the way that the mobile apps or websites communicate and transmit data to servers and vice-versa. There are a set HTTP Requests posting and getting data to and from servers over internet.

Which technology is best for REST API?

Postman. “It is probably the most popular tool for testing your REST API. If you take a look at their website, you'll find that Postman is used by 5 million developers and over 100,000 businesses to access 130 million APIs each month. It is also feature rich and supports all stages of the REST API life cycle.

Can we use browser to call REST API?

The REST API uses several HTTP methods to perform various actions on REST resources. Any REST API call that uses the HTTP GET method can be submitted using a Web browser such as Microsoft Internet Explorer or Mozilla Firefox.


2 Answers

I would recommend checking out RestKit: http://restkit.org/ It provides an excellent API for accessing RESTful web services and representing the remote resources as local objects, including persisting them to Core Data. HTTP authentication is supported out of the box.

like image 149
Blake Watters Avatar answered Sep 22 '22 05:09

Blake Watters


I'm new to iOS development and I've been battling with some of the big frameworks listed on this page for the past month or so. It has been a nightmare. I'd honestly recommend you just stick to the basics and do it yourself using AFNetworking or Apple's own NSURLConnection.

One of the libraries listed is no longer maintained. Another underwent huge code-breaking API changes recently and now half of the tutorials describing its use no longer work. Others are massively bloated.

It's easier than you'd think. Some resources that helped me:

  • http://blog.strikeiron.com/bid/63338/Integrate-a-REST-API-into-an-iPhone-App-in-less-than-15-minutes
  • http://www.slideshare.net/gillygize/connecting-to-a-rest-api-in-ios

The examples on the AFNetworking homepage alone may get you 80% of the way there.

UPDATE: The Mantle Framework (open sourced by Github Inc.) is well-designed and easy to use. It handles object mapping: converting a JSON NSDictionary to your own custom Objective-C model classes. It handles default cases sensibly and it's pretty easy to roll your own value transformers, e.g. from string to NSURL or string to your custom enum.

like image 39
bcattle Avatar answered Sep 21 '22 05:09

bcattle