TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Apr 2015 |
Maintained by Klaas Pieter Annema.
Depends on: | |
InflectorKit | = 0.0.1 |
DCKeyValueObjectMapping | ~> 1.4 |
APIClient is a convention over configuration REST API client for Objective-C. APIClient attempts to do as little as possible to deal with conventional REST APIs. If you're dealing with an unconventional API it's trivial to override the default behavior by implementing the protocols APIClient exposes.
There are two main ways to instantiate an APIClient instance. The first is by providing a baseURL:
APIClient *client = [APIClient clientWithBaseURL:baseURL];
And the second by providing a configuration block:
APIClient *client = [APIClient clientWithConfigurationBlock:^(APIClientConfiguration *config) {
config.baseURL = baseURL;
}];
The configuration block is passed a APIClientConfiguration
instance which you can use to customize the components used by your client.
Take a look at the APIClientConfiguration header to learn what can be customized.
APIResponse *response = [_client findAll:[Product class]];
response.success = ^(NSArray *products) {
NSLog(@"products: %@", products);
};
response.failure = ^(NSError *error) {
NSLog(@"error: %@", error);
};
APIResponse *response = [_client findResource:[Product class] withID:@1];
response.success = ^(Product *product) {
NSLog(@"product: %@", product);
};
response.failure = ^(NSError *error) {
NSLog(@"error: %@", error);
};
Any APIClient request follows a number of steps. The entire process is as follows:
Every step is abstracted into different components. An APIClient component is a formal protocol and a default implementation of that protocol that follows REST conventions. If you need different behavior you can either create a subclass of APIClient's implentation or create your own class that conforms to the protocol.
Klaas Pieter Annema, [email protected]
APIClient is available under the MIT license. See the LICENSE file for more info.