Skip to content

flambert/SVHTTPRequest

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SVHTTPRequest

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

Installation

  • Drag the SVHTTPRequest/SVHTTPRequest folder into your project.

Usage

(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.

Cancelling requests

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];

Connection errors

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).

Signing requests for basic auth

You can easily sign your requests for basic authentication using similar convenience methods:

[SVHTTPRequest POST:address
         parameters:parameters 
           username:username
           password:password
         completion:completionBlock];

Credits

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.

About

Straightforward GET and POST requests for your iOS app.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published