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
900
Swift Package Manager
neonichu
2
330
Swift Package Manager
neonichu
0
52
📺
neonichu
0
2k
Cross-Platform Swift
neonichu
0
79
Swift Package Manager
neonichu
6
4.3k
Other Decks in Programming
See All in Programming
Windows版PHPのビルド手順とPHP 8.4における変更点
matsuo_atsushi
0
360
PHPer's Guide to Daemon Crafting Taming and Summoning
uzulla
2
920
ベクトル検索システムの気持ち
monochromegane
28
8.4k
Devinのメモリ活用の学びを自社サービスにどう組み込むか?
itarutomy
0
1.5k
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
300
AHC 044 混合整数計画ソルバー解法
kiri8128
0
290
生産性アップのためのAI個人活用
kunoyasu
0
470
AI時代のプログラミング教育 / programming education in ai era
kishida
22
20k
Devin入門と最近のアップデートから見るDevinの進化 / Introduction to Devin and the Evolution of Devin as Seen in Recent Update
rkaga
7
3.4k
いまさら聞けない生成AI入門: 「生成AIを高速キャッチアップ」
soh9834
11
3.4k
Functional APIから再考するLangGraphを使う理由
os1ma
5
640
新卒から4年間、20年もののWebサービスと 向き合って学んだソフトウェア考古学
oguri
7
6.4k
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
67
11k
The Language of Interfaces
destraynor
156
24k
Navigating Team Friction
lara
183
15k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
How GitHub (no longer) Works
holman
314
140k
A Modern Web Designer's Workflow
chriscoyier
693
190k
RailsConf 2023
tenderlove
29
1k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Building an army of robots
kneath
304
45k
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 boris@contentful.com https://github.com/neonichu http://buegling.com/talks http://www.contentful.com