title: Encapsulating AFRequestOperationManager with a class and make it available app wide
body: <p>I am new to Obj C (rubyist here!) so I'm not sure how to go about this. So we use AFNetworking in our app which communicates to our server via a JSON API. Looking at the code right now, there is much repetition, and based on my background, I have a penchant for not being repetitive so we're aiming to refactor this into just one class. The best would be to include it app-wide so we can just access a variable or a method whenever we want to pull something from the server.</p>
  
  <p>Anyway, what we have now is something to this effect:</p>
  
  <pre><code>AFHTTPRequestManager *manager = [AFHTTPRequestOperationManager manager];
  manager.responseSerializer = [AFJSONResponseSerializer serializer];
  manager.requestSerializer = [AFJSONRequestSerializer serializer];
  [manager.requestSerializer setValue:'some@email.com' forHTTPHeaderField:@"EMAIL"
  ...
  
  [manager GET:url parameters:parameters success:^ (AFHTTPRequestOperation *operation, id responseObject) {
     // do most of the stuff here
  } failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
     NSLog(@"Error: %@", error);
  }
  </code></pre>
  
  <p>that's the basic functionality of the method we want to try to make. Most of our API calls (in different custom controllers) are using this pattern. I was thinking, maybe we can pull it out of all the controllers and make it into a class with a method like <code>getResponseObject</code> or something because basically that's the only thing we need - a responseObject of the JSON returned by the server.</p>
  
  <p>Also, we are planning to make it available to the whole app, since most of the app are just API calls to the server. Right now we have sort-of encapsulated it into a custom class - but I think if I understand it, every time we do an API call, that class will be created/allocated? Is it advisable to just create that single instance of a class in AppDelegate so it can be available at any time?</p>
  
  <p><em>EDIT</em></p>
  
  <p>we are trying to encapsulate these methods: <a href="https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/AFHTTPRequestOperationManager.m#L114-L182" rel="nofollow">https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/AFHTTPRequestOperationManager.m#L114-L182</a> into just one method that takes in the request type as a string (GET, PUT, POST etc). </p>