Skip to content

Instantly share code, notes, and snippets.

@dtorres
Created June 19, 2015 21:20
Show Gist options
  • Save dtorres/f596bb5d0a2f308b7e99 to your computer and use it in GitHub Desktop.
Save dtorres/f596bb5d0a2f308b7e99 to your computer and use it in GitHub Desktop.

It wasn´t hard. We needed to reimplement/copy a few things that were taken for granted in AFNet such as user agent, accept and other headers. Those were easy to do with NSURLSessionConfiguration.

In terms of request and url construction they are created by each model doing the request, it is a bit more of code and maybe duplicated but explicit as there is no implicit baseURL. The query/body is also constructed in place being explicit and not having to worry if the serializer is JSON or form data. Also it has the advantage of performance since the request serializer of AFNetworking creates mutable copies the request around a lot to do checks in methods that take immutable ones.

Also I created this category for convenience

@interface NSMutableURLRequest (JSONBody)

- (void)setJSONBody:(id)body;
- (BOOL)setJSONBody:(id)body options:(NSJSONWritingOptions)options error:(NSError **)error;

@end```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment