Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Designing mobile APIs
Search
Radoslav Stankov
November 30, 2013
Technology
3
220
Designing mobile APIs
Video:
https://www.youtube.com/watch?v=Y6LiPJV0EH4
Radoslav Stankov
November 30, 2013
Tweet
Share
More Decks by Radoslav Stankov
See All by Radoslav Stankov
Rails: The Missing Parts
rstankov
1
18
The dream that turned into nightmare
rstankov
0
87
The dream that turned into nightmare (lightning)
rstankov
0
33
Ruby on Rails - The Single Engineer Framework
rstankov
0
230
Living Without Exceptions
rstankov
1
190
One engineer company with Ruby on Rails
rstankov
2
640
Eliminating noise from your code
rstankov
0
92
Best JavaScript is No Javascript
rstankov
0
130
React Mid Game
rstankov
2
110
Other Decks in Technology
See All in Technology
Behind the scenes of 24-hour global online event “JAWS PANKRATION 2024”
syoshie
0
110
実践/先取り「入門 Kubernetes Validating/Mutating Admission Policy」 / CloudNative Days Winter 2024
pfn
PRO
1
130
Windows Server 2025 Pay as you Go ライセンスを試す
murachiakira
0
180
Microsoft 365と開発者ツールの素敵な関係
kkamegawa
1
1.1k
LINEヤフーにおける超大規模プラットフォーム実現への挑戦と学び / Challenges and Lessons in Building an Ultra-Large-Scale Platform at LY Corporation
hhiroshell
1
840
全社員に向けて生成AI活用を促進!~電通総研の生成AI活用ロードマップ~
iotcomjpadmin
0
170
セキュリティベンダー/ユーザー双方の視点で語る、 Attack Surface Managementの実践 - Finatextパート / cloudnative-architecture-of-asm
stajima
0
2.5k
2024/11/29_失敗談から学ぶ! エンジニア向けre:Invent攻略アンチパターン集
hiashisan
0
170
2024年のAmazon Bedrockアップデート一挙おさらい 〜まだ間に合う! re:Invent直前までの重大ニュースを速習しよう〜
minorun365
PRO
3
160
Amazon Forecast亡き今、我々がマネージドサービスに頼らず時系列予測を実行する方法
sadynitro
0
220
データ共有による新しい価値の創造
iotcomjpadmin
0
180
歴史あるRuby on Railsでデッドコードを見つけ、 消す方法@yabaibuki.dev #3
ayumu838
0
1.7k
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
400
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.3k
The Cult of Friendly URLs
andyhume
78
6.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
470
Navigating Team Friction
lara
183
15k
Optimizing for Happiness
mojombo
376
70k
RailsConf 2023
tenderlove
29
910
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Designing for humans not robots
tammielis
250
25k
Making Projects Easy
brettharned
115
5.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Transcript
Radoslav Stankov BlagoevgradConf 2013 30/11/2013 Designing Mobile APIs
Radoslav Stankov @rstankov ! ! ! ! http://rstankov.com http://github.com/rstankov
None
I have a plan!
None
1.Versioning 2.Headers 3.Error responses 4.Authentication 5.REST Agenda
Mobile in numbers
None
Web App Mobile API
Mobile API
Example
1.Versioning 2.Headers 3.Error responses 4.Authentication 5.REST Agenda
1.Versioning! 2.Headers 3.Error responses 4.Authentication 5.REST Agenda
Versioning
http://fantasy-football.com/api/v1/team/1.json
http://fantasy-football.com/api/v1/team/1.json
https://fantasy-football.com/api/v1/team/1.json
https://fantasy-football.com/api/v1/team/1.json
https://fantasy-football.com/api/v1/team/1.json
https://mobile.fantasy-football.com/v1/team/1.json
https://mobile.fantasy-football.com/v1/team/1.json
https://mobile.fantasy-football.com/v1/team/1.json
Content-Types that are acceptable for the response. Accept Header
https://mobile.fantasy-football.com/v1/team/1.json
Accept: application/json https://mobile.fantasy-football.com/v1/team/1.json
Accept: application/json https://mobile.fantasy-football.com/v1/team/1
Accept: application/json https://mobile.fantasy-football.com/v1/team/1
Accept: application/vnd.football-team.com; version=1, application/json https://mobile.fantasy-football.com/v1/team/1
Accept: application/vnd.football-team.com; version=1, application/json https://mobile.fantasy-football.com/team/1
1.Versioning! 2.Headers 3.Error responses 4.Authentication 5.REST Agenda
1.Versioning 2.Headers! 3.Error responses 4.Authentication 5.REST Agenda
Headers
User-Agent User-Agent: iOS 7.1
Accept-Language Accept-Language: en
! • X-Api-Key • X-Push-Notification-Id • X-Checksum • …. Custom
! • X-Api-Key • X-Push-Notification-Id • X-Checksum • …. Custom
1.Versioning 2.Headers! 3.Error responses 4.Authentication 5.REST Agenda
1.Versioning 2.Headers 3.Error responses! 4.Authentication 5.REST Agenda
Error responses
HTTP Statuses Code Description 400 Bad Request 401 Unauthorized 402
Account Is Locked 404 Not Found 405 Method Not Allowed 422 Unprocessable Entity 426 To Many Requests 500 Internal Server Error
HTTP Statuses http://httpstatus.es/
Response Body { “message”: “Invalid api key” } GET https://mobile.fantasy-football.com/teams/1
422 - Unprocessable Entity { “errors”: { “name”: [“Already taken”],
“budget”: [“Must be more than 0”] } } POST https://mobile.fantasy-football.com/teams/
1.Versioning 2.Headers 3.Error responses! 4.Authentication 5.REST Agenda
1.Versioning 2.Headers 3.Error responses 4.Authentication! 5.REST Agenda
Authentication
WWW-Authentication > WWW-Authenticate: Basic realm=“Fantasy Football” ! < Authorization: Basic
QWxhZGRpbjpvcGVuIHNlc2FtZQ==
WWW-Authentication > WWW-Authenticate: Digest realm=“Fantasy Football", … ! < Authorization:
Digest username=“User", …
WWW-Authentication Authorization: Token token=“7C1100AD4A6D45A6B2E022B”
None
Public ~ vs ~ Private
OAuth ~ vs ~ Token
OAuth ~ vs ~ Token
Tokens Method URL Description POST /token Create new token (with
login credentials) DELETE /token Delete token HEAD /token Check if token is active PATCH /token Renew a token (if tokens can expire)
1.Versioning 2.Headers 3.Error responses 4.Authentication! 5.REST Agenda
1.Versioning 2.Headers 3.Error responses 4.Authentication 5.REST Agenda
REST
Teams Method URL Description GET /my/teams Returns all teams POST
/my/teams Create new team GET /my/teams/1 Return given team PATCH /my/teams/1 Update given team DELETE /my/teams/1 Delete given team
{ “id”: 1, “name”: “Real Blagoevgrad”, “players”: { /* players
*/ } } POST /my/teams Accept: application/vnd.fantasy-football.com; version=1,application/json Authentication: Token token=“0BD8AF0AAB86619” X-Api-Key: “7C1100AD4A6D45A6B2E022B”
{ “id”: 1, “name”: “Real Blagoevgrad”, “players”: { /* players
*/ } } GET /my/teams/1 Accept: application/vnd.fantasy-football.com; version=1,application/json Authentication: Token token=“0BD8AF0AAB86619” X-Api-Key: “7C1100AD4A6D45A6B2E022B”
{ “id”: 1, “name”: “Bayern Blagoevgrad”, “players”: { /* players
*/ } } PATCH /my/teams/1 Accept: application/vnd.fantasy-football.com; version=1,application/json Authentication: Token token=“0BD8AF0AAB86619” X-Api-Key: “7C1100AD4A6D45A6B2E022B”
GET /teams Accept: application/vnd.fantasy-football.com; version=1,application/json Authentication: Token token=“0BD8AF0AAB86619” X-Api-Key: “7C1100AD4A6D45A6B2E022B”
[{ “id”: 1, “name”: “Bayern Blagoevgrad”, “owner”: { /* owner */ }, “players”: { /* players */ }, }, { /* other team */ }]
Paging (1) X-Total: 10 X-Offset: 2 X-Offset: 3
Paging (2) Link: <https://fantasy-football.com/teams/?page=3>; rel="next", <https://fantasy-football.com/teams/?page=1>; rel=“previous”, <https://fantasy-football.com/teams/?page=1>; rel=“first”, <https://fantasy-football.com/teams/?page=100>;
rel=“last”
Paging (3) Link: <https://fantasy-football.com/teams/?after-id=1213>; rel="next"
1.Versioning 2.Headers 3.Error responses 4.Authentication 5.REST Agenda
Bonus
Mobile API ~ vs ~ Regular API
Syncing / Offline
Postman Chrome plugin
Good API example http://developer.github.com/v3/
Questions?
@rstankov Thank you :)