title: writing an API class for RestKit framework
body: <p>I switched from AFnetworking to RestKit. In AFnetworking had an API class. The API.h class contained the following. </p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  typedef void (^JSONResponseBlock)(NSDictionary* json);
  @interface API : NSObject
  //the authorized user
  @property (strong, nonatomic) NSDictionary* user;
  
  +(API*)sharedInstance;
  //check whether there's an authorized user
  
  //send an API command to the server
  -(void)loginCommand:(NSMutableDictionary*)params onCompletion:(JSONResponseBlock)completionBlock;
  </code></pre>
  
  <p>And my API.m class looks like this.</p>
  
  <pre><code>+(API *)sharedInstance
  {
      static API *sharedInstance = nil;
      static dispatch_once_t oncePredicate;
      dispatch_once(&amp;oncePredicate, ^ {
          sharedInstance = [[self alloc]initWithBaseURL:[NSURL URLWithString:kAPIHost]];
      });
      return sharedInstance;
  }
  
  #pragma mark - init
  //intialize the API class with the destination host name
  
  -(API *)init
  {
      //call super init
      self = [super init];
  
      if (self != nil){
          //initialize the object
          user = nil;
  
          [self registerHTTPOperationClass:[AFJSONRequestOperation class]];
  
          // Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
          [self setDefaultHeader:@"Accept" value:@"application/json"];
      }
      return self;
  }
  
  -(void)loginCommand:(NSMutableDictionary *)params onCompletion:(JSONResponseBlock)completionBlock{
      NSLog(@"%@%@",kAPIHost,kAPILogin);
      NSMutableURLRequest *apiRequest = [self multipartFormRequestWithMethod:@"POST" path:kAPILogin parameters:params constructingBodyWithBlock:^(id &lt;AFMultipartFormData&gt;formData){
          //TODO: attach file if needed
  
      }];
      AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:apiRequest];
      [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
          //success!
          NSLog(@"SUCCESSSS!");
          completionBlock(responseObject);
      }failure:^(AFHTTPRequestOperation *operation, NSError *error){
          //Failure
          NSLog(@"FAILUREE!");
          completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
      }];
      [operation start];
  
  }
  </code></pre>
  
  <p>Like you can see I only instantiate it once and put all my methods in over here. In my view controller I only need to call this method with a parameter-dictionary. Then I could read the whole JSON file. </p>
  
  <p>Now with restKit I do this all on viewController level. I want to split it up like I did by AFNetworking. This is what I do in RestKit, At the moment is this all on viewController level.</p>
  
  <pre><code>   //let AFNetworking manage the activity indicator
  [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
  
  // Initialize HTTPClient
  NSURL *baseURL = [NSURL URLWithString:@"http://virtuele-receptie.preview.sanmax.be"];
  AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
  //we want to work with JSON-Data
  [client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
  
  // Initialize RestKit
  RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
  
  
  //Do mapping
  
  RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dataMapping
                                                                                     pathPattern:nil
                                                                                         keyPath:@"data"
                                                                                     statusCodes:[NSIndexSet indexSetWithIndex:200]];
  [objectManager addResponseDescriptor:responseDescriptor];
  
  NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:_txtLogin.text,@"email",_txtPass.text,@"pwd", nil];
  
  [objectManager getObject:nil path:@"/nl/webservice/company-user/login/apikey/key12345678" parameters:dict
                   success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                     //Success  
                   }
                   failure:^(RKObjectRequestOperation *operation, NSError *error) {
                       //Failure
                   }];
  </code></pre>