iOS Most mature REST service library

2019-02-27 04:04发布

If I want to hit REST services from an iOS app what is the most mature library for doing so? What are my best options?

标签: ios rest
5条回答
叛逆
2楼-- · 2019-02-27 04:32

Not so mature but very light weight: JNRestClient

查看更多
可以哭但决不认输i
3楼-- · 2019-02-27 04:33

You can use RestKit.

Or you can use NSJSONSerialization which is already in the foundation framework.

Here's an exemple from a project that i made. It fetch an array of drinks from a json webservice:

 NSString *urlString= [NSString stringWithFormat:@"my json webservice URL"];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
NSDictionary *jsonResultSet = (NSDictionary*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if ([jsonResultSet count] !=0){
    NSArray* drinks = [jsonResultSet objectForKey:@"drinks"];
    for (NSDictionary* drinkDictionary in drinks) {
        Drink* drink = [[Drink alloc] initWithDictionary:drinkDictionary];
        [[DrinkList getInstance]addDrinksWithObject:drink];
    }
}
查看更多
叼着烟拽天下
4楼-- · 2019-02-27 04:40

There is also the new swift rest library called Alamofire (https://github.com/Alamofire/Alamofire), it seems really nice, it has already more than 6000 stars on github and it has been created by Mattt Thompson which means you can go for it without worries.

查看更多
forever°为你锁心
5楼-- · 2019-02-27 04:46

JSONModel is quite simple to use.

Overcoat+Mantle look really good.

RestKit is a bit verbose, IMHO.

查看更多
SAY GOODBYE
6楼-- · 2019-02-27 04:50

I recommend AFNetworking. The following is a sample code taken from its Github page (there is more samples over there):

NSURL *url = [NSURL URLWithString:@"https://alpha-api.app.net/stream/0/posts/stream/global"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@"App.net Global Stream: %@", JSON);
} failure:nil];
[operation start];

Other alternatives are:

Of them all, I think both AFNetworking and RestKit are the most popular. I personally have used extensively AFNetworking, thus why I recommend it.

查看更多
登录 后发表回答