Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Build better API clients
Search
Boris Bügling
April 24, 2015
Programming
0
130
Build better API clients
Some thoughts on building better API clients, talk given at APIDays Berlin 2015.
Boris Bügling
April 24, 2015
Tweet
Share
More Decks by Boris Bügling
See All by Boris Bügling
Testing ⌚️ Apps and Other Extensions
neonichu
1
4.6k
Cross-platform Swift
neonichu
4
18k
Building better API clients in Swift
neonichu
1
290
Cross-platform Swift
neonichu
3
880
Swift Package Manager
neonichu
2
320
Swift Package Manager
neonichu
0
50
📺
neonichu
0
2k
Cross-Platform Swift
neonichu
0
74
Swift Package Manager
neonichu
6
4.3k
Other Decks in Programming
See All in Programming
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
520
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
Quine, Polyglot, 良いコード
qnighy
4
640
初めてDefinitelyTypedにPRを出した話
syumai
0
400
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
距離関数を極める! / SESSIONS 2024
gam0022
0
280
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
65
11k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Bash Introduction
62gerente
608
210k
Designing for Performance
lara
604
68k
What's new in Ruby 2.0
geeforr
343
31k
How to train your dragon (web standard)
notwaldorf
88
5.7k
GitHub's CSS Performance
jonrohan
1030
460k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
BBQ
matthewcrist
85
9.3k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Become a Pro
speakerdeck
PRO
25
5k
Transcript
BETTER API CLIENTS APIDAYS BERLIN, APRIL 2015 BORIS BÜGLING -
@NEONACHO
COCOAPODS
CONTENTFUL
None
None
None
source: http://appreviewtimes.com
Mobile apps need to be more reliable than the web.
None
Let's build better API clients to help building better apps
OPEN SOURCE
None
DOCUMENTATION
/** The server address to use for accessing any resources.
Default value: "cdn.contentful.com" */ @property (nonatomic) NSString* server; /** Configure a custom user-agent to be used in the HTTP request headers */ @property (nonatomic) NSString* userAgent;
None
COCOAPODS-DOCSTATS $ pod lib docstats 398 tokens, 100.0% documented
TESTING
let expectation = expectationWithDescription("...") waitForExpectationsWithTimeout(10) { (error) in // ...
} expectation.fulfill()
API BLUEPRINT # GET /message + Response 200 (text/plain) Hello
World!
CCLREQUESTREPLAY NSURL *blueprintURL = [[NSBundle mainBundle] URLForResource:@"fitnessfirst" withExtension:@"apib"]; CCLRequestReplayManager *replayManager
= [CCLRequestReplayManager managerFromBlueprintURL:blueprintURL error:nil]; [replayManager replay];
None
COCOAPODS-COVERAGE pod lib coverage
DISTRIBUTION
"Download the SDK from our webpage."
None
pod 'ContentfulDeliveryAPI'
COCOAPODS-PACKAGER pod package ContentfulDeliveryAPI.podspec
None
spec.dependency 'AFNetworking', '>= 2.5.2'
SO, WE'RE DONE, RIGHT?
ANTICIPATING CHANGE IS ONE OF THE CENTRAL THEMES OF REST.
Example: creating a poll
<html> <body> <h1>Poll</h1> <ul> <li><a href="/questions/new" rel="create">Make a new question</a></li>
</ul> </body> </html>
▸ Offers us to create a question ▸ We can
fill in the form we get ▸ Submit the form
We can do the same in our apps with Hypermedia
FORMATS ▸ HAL (application/hal+json) ▸ Siren (application/vnd.siren+json)
SIREN LINK { "entities": [ { "links": [ { "rel":
["self"], "href": "questions/1/choices/1" } ], "rel": ["choices"], "properties": { "choice": "Swift", "votes": 22 } } ] }
SIREN ACTION { "actions": { "create": { "href": "/questions", "method":
"POST", "fields": [ { "name": "question" }, { "name": "choices" } ], "type": "application/x-www-form-urlencoded" } } }
WE CAN NOW CHANGE IMPLEMENTATION DETAILS ON THE FLY
CHANGE URIS OF RESOURCES e.g. /polls/{id} to /questions/{id}
CHANGE HTTP METHODS e.g. PUT to POST
CHANGE THE CONTENT-TYPE
CHANGE FIELDS USED IN FORMS
REPRESENTOR
PRESENCE OF A TRANSITON if let transition = representor.transitions["create"] {
} else { // ... }
ATTRIBUTES OF A TRANSITION if let transition = representor.transitions["create"] {
transition.method transition.uri transition.suggestedContentType }
PERFORMING A TRANSITION request(transition, attributes: [ "question": "Favourite programming language?",
"choices": [ "Swift", "Ruby", "COBOL" ] ])
None
WHAT HAVE WE LEARNED? ▸ Publish source code! ▸ Document!
▸ Test! ▸ Be robust against change!
THANK YOU!
@NeoNacho
[email protected]
https://github.com/neonichu http://buegling.com/talks http://www.contentful.com