This is a scaffold library and the aid of the project is providing all foundation functions for IOS
developer to build app easier.
Network function usually can work with AsyncHelper's RunInBackground function together to provide async operation.
* Network engine already updated, please see unit test of RESTRequestTests to know the latest usage.
You can get data with NSDictionary or NSArray format as the example:
NSDictionary* _dictionaryResult = [A_RESTRequest A_GetDictionary:@"yoururl"
Parameters:@{@"key1":@"value"}
Headers:@{@"Accept":@"application/json"}];
NSArray* _arrayResult = [A_RESTRequest A_GetArray:@"yoururl"
Parameters:@{@"key1":@"value"}
Headers:@{@"Accept":@"application/json"}];
RESTRequest provide 4 methods of posting data. You can post data with pure JSON or query way; also, you can get data with NSDictionary or NSArray format as the example:
// Post data with query way, such as "key1=value1&key2=value2"
[A_RESTRequest A_PostQueryReturnArray:@"yoururl"
Parameters:@{@"key1":@"value1", @"key2":@"value2"}
Header:nil];
[A_RESTRequest A_PostQueryReturnDictionary:@"yoururl"
Parameters:@{@"key1":@"value1", @"key2":@"value2"}
Header:nil];
// Post data with json way, such as "{key1:value1,key2:value2}"
[A_RESTRequest A_PostJSONReturnArray:@"yoururl"
Parameters:@{@"key1":@"value1", @"key2":@"value2"}
Header:@{@"Content-Type":@"application/json; charset=utf-8"}];
[A_RESTRequest A_PostJSONReturnArray:@"yoururl"
Parameters:@{@"key1":@"value1", @"key2":@"value2"}
Header:@{@"Content-Type":@"application/json; charset=utf-8"}];
UIImage* _image = [A_ImageHelper A_GetImageByNamed:@"example.png"];
[A_RESTRequest A_UploadImage:@"yoururl"
QueryParameters:@{@"key1":@"value1"}
Headers:nil Image:_image
FileName:@"example.png"
FileKey:@""];
You can customize your request with request method (GET,POST,PUT,DELETE) and format (JSON,QUERY). Moreover, you can use JSONHelper to convert NSData to NSArray or NSDictionary.
NSData* _result = [A_RESTRequest A_Request:@"yoururl"
Parameters:@{@"key1":@"value1", @"key2":@"value2"}
Headers:@{@"Content-Type":@"application/json; charset=utf-8"}
Method:A_Network_PUT //GET,POST,PUT,DELETE
ParamFormat:A_Network_SendAsJSON]; //JSON,QUERY
NSDictionary* _dictionary = [A_JSONHelper A_ConvertJSONDataToDictionary:_result];