SVHTTPRequest is a simple and extremely straightforward alternative to bulky ASIHTTPRequest. It is blocked-based, uses NSURLConnection and its only 3rd party dependancy is the blazing fast JSONKit (included in package).
SVHTTPRequest features:
- straightforward singleton convenience methods
- completion block handler
- response is automatically parsed (if applicable) and forwarded to completion block
- support for basic authentication request signing
- talks with
setNetworkActivityIndicatorVisible
- Drag the
SVHTTPRequest/SVHTTPRequest
folder into your project.
(see sample Xcode project in /Demo
)
SVHTTPRequest was designed to be the most straightforward possible:
[SVHTTPRequest GET:@"http://api.twitter.com/1/users/show.json" parameters:[NSDictionary dictionaryWithObject:@"samvermette" forKey:@"screen_name"] completion:^(NSObject *response) { NSLog(@"%@", response); }];
By now you’ve probably guessed how to make a POST request.
Make sure you cancel requests for which the user isn’t waiting on anymore:
SVHTTPRequest *request = [SVHTTPRequest GET:@"http://api.twitter.com/1/users/show.json" parameters:[NSDictionary dictionaryWithObject:@"samvermette" forKey:@"screen_name"] completion:^(NSObject *response) { NSLog(@"%@", response); }]; [request cancel];
Requests that fail will report back to the completion block with a nil
response object. You can also use the response object to detect errors, depending on the type of call you’re making (for instance you were expecting a JSON object and it’s not, or if the server itself is providing you with error descriptions).
You can easily sign your requests for basic authentication using similar convenience methods:
[SVHTTPRequest POST:address parameters:parameters username:username password:password completion:completionBlock];
SVHTTPRequest is brought to you by Sam Vermette (@samvermette) and contributors to the project. If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by creating new issues. If you’re using SVHTTPRequest in your project, attribution would be nice.