• This repository has been archived on 25/Apr/2023
  • Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convention over configuration REST API client for Objective-C

APIClient

Swift happened. This was fun, but I have no intention to develop this further.

Installation

APIClient is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "APIClient"

Introduction

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.

Usage

Instantiating

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.

GET a resource collection

APIResponse *response = [_client findAll:[Product class]];
response.success = ^(NSArray *products) {
    NSLog(@"products: %@", products);
};
response.failure = ^(NSError *error) {
    NSLog(@"error: %@", error);
};

GET a single resource

APIResponse *response = [_client findResource:[Product class] withID:@1];
response.success = ^(Product *product) {
    NSLog(@"product: %@", product);
};
response.failure = ^(NSError *error) {
    NSLog(@"error: %@", error);
};

Process

Any APIClient request follows a number of steps. The entire process is as follows:

  1. Ask the APIRouter to map an action on a resource to a URL. For example GET MyProduct becomes URL https://yourbaseurl.com/products
  2. Make a request for the URL using the HTTPClient
  3. Use the serializer to serialize the response body to Foundation objects
  4. Map the Foundation objects to instances of the requested resource

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.

Authors

Klaas Pieter Annema, [email protected]

License

APIClient is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

coc-sourcekit

Swift language server extension using sourcekit-lsp for coc.nvim.
JavaScript
73
star
2

chxcode

Changes the current Xcode
Makefile
68
star
3

KPAViewControllerTestHelper

Convenience class for testing view controllers
Objective-C
38
star
4

xcrecord

Capture GIFs from the iOS simulator πŸŽ₯
Shell
30
star
5

Letters

Mac app to learn typing and the alphabet
Swift
27
star
6

objc-io-issue-15-ux-testing

A sample project showing methods to test user behavior
Objective-C
23
star
7

KPAStoryboardConvenience

A UIStoryboard convenience category offering a standard way of naming and accessing components in storyboards
Objective-C
17
star
8

KPUIKit

KPUIKit is a Cappuccino framework that makes it easier to handle complex single window applications.
Objective-J
13
star
9

KPAColorFormatter

A NSFormatter subclass that can format instances of UIColor or NSColor to their textual representation
Objective-C
13
star
10

Numeric

Numeric extensions for Swift
Swift
9
star
11

cappuccino-comparisons

A collection of Cappuccion vs Cocoa comparison applications
Objective-C
8
star
12

asdf-xcode

Shell
7
star
13

configuration

An example application showing how an iOS project can be configured for multiple environments
Objective-C
7
star
14

autonib2cib

Automatically nib2cib changed nibs in a directory
Python
6
star
15

Inhabited

A Swift Collection that can never be empty
Swift
6
star
16

Moses

An OAuth2 client written in Swift
Swift
3
star
17

dotfiles

My dotfiles
Lua
2
star
18

minimal

A very minimal Ghost theme inspired by https://thebestmotherfucking.website/
HTML
2
star
19

uispecta

A Matcher Framework for UIKit
Objective-C
2
star
20

kitty-whitescale

A whitescale colorscheme meant to keep its colors in white, black, and gray.
Shell
2
star
21

Cedule

Terrible idea
Objective-C
1
star
22

FakeQL

Automatic GraphQL mocks
TypeScript
1
star
23

annemame

My personal website
HTML
1
star
24

checkout-ios

Stripe Checkout for iOS
Objective-C
1
star
25

swift-emoji

Turn Slack-like emoji shortcuts into their Unicode representations
Swift
1
star