Making simple REST calls in Objective-C
I was looking to make REST calls to an API for a Mac application I was working on, and I kept looking for a way to do this, and ran into really useful (but huge) libraries like Restkit. But doing this effectively doubled the size of my executable .app file.
Turns out, Foundation provides an NSURLRequest class, which makes making REST calls really easy-peasy, and just a few lines of code.
First, I created an instance method.
Then, I call it.
But, so you’re not happy with a simple REST call and wish to add an HTTP header. Easy as pie! We need to use an object of NSMutableURLRequest and cast it back, if required.
I’m sure RestKit is a wonderful library, but for making a single RESTful URL request, it is overkill!