-
Notifications
You must be signed in to change notification settings - Fork 9
API Blueprint
This document describes how to add and use the API Blueprint adapter in the Representor.
Installation with CocoaPods is recommended using CocoaPods 0.36.
pod 'Representor'Alternatively, you can clone Representor via git or as a submodule and include Representor.xcodeproj inside your project and add Representor.framework as a target dependency.
The next step is to include your blueprint into your project, for this you will need to grab a JSON representation of the blueprint.
We're going to use a command line tool called Snowcrash to do this.
NOTE: This depends on the Homebrew package manager.
$ brew install --HEAD https://raw.github.com/apiaryio/snowcrash/master/tools/homebrew/snowcrash.rbNow we have Snowcrash installed, we can generate the JSON representation of our blueprint (blueprint.md):
$ snowcrash -o blueprint.ast.json -f json blueprint.md
OK.This will output a blueprint.ast.json which we will need to add to our Xcode project.
Now we're ready to access our blueprint at runtime. Given an action called "Create" in a resource named "Polls", which looks something like this in our blueprint:
## Polls [/polls]
### Create [POST]We can now pull that out at run-time using the following:
let blueprint = Blueprint(named: "blueprint.ast.json", bundle: nil)
if let transition = blueprint?.transition("Polls", action: "Create") {
println("We can perform this action via the HTTP method: \(transition.method) with the URI: \(transition.uri).")
}We can use Alamofire to perform this action as follows:
let baseURL = NSURL(string: "https://pollsapi.herokuapp.com/")
request(baseURL, transition, parameters: nil, attributes: nil).responseJSON {
(_, _, json, _) in
println(json)
}