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
Creating a RESTful API for mobile applications
Search
Paul McMahon
March 25, 2013
Technology
310
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Creating a RESTful API for mobile applications
Presented at
http://www.tokyorubyistmeetup.org/events/2814
Paul McMahon
March 25, 2013
More Decks by Paul McMahon
See All by Paul McMahon
Why Ember.js?
pwim
0
1.1k
JSON API
pwim
0
140
A developer's perspective on entrepreneurship
pwim
1
390
Using GitHub to get a better job
pwim
11
2.3k
Using Analytics to Improve UX
pwim
0
3.4k
Event Organizers Co-Edo edition
pwim
0
2.9k
勉強会を開催する大まかな流れ
pwim
2
10k
Creating International Communities in Japan
pwim
0
220
英語でコミットを書こう
pwim
52
28k
Other Decks in Technology
See All in Technology
アップデートで何が変わった?デモで学んで使いこなすIBM Bob2.0
muehara
0
170
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
1
5.2k
Network Firewallやっていき!
news_it_enj
0
170
インシデント事例と パッケージの全量解析に学ぶ ソフトウェアサプライチェーンの守り方 / supply-chain-attack-defense
flatt_security
0
120
LLMやAIエージェントをソフトウェアに組み込むプラクティス
shibuiwilliam
2
430
AIとハーネスで育てるトランスコンパイラ / 20260722 Yasushi Katayama
shift_evolve
PRO
0
110
最適な自走を最小限の支援で — M&Aで拡大する組織で少人数SREが挑んだ1年 / SRE NEXT 2026
genda
0
1.5k
凡エンジニアがこの先生きのこるためには。〜TypeScript完全に理解したい〜
alchemy1115
2
310
AIと共生する開発者プラットフォーム:バクラクのモノレポ×マイクロサービス基盤
sakajunquality
2
4k
誤解だらけの開発生産性 / Myths and Misconceptions about Developer Productivity
i35_267
2
820
【Claude Code】鹿野さんに聞く 私の推しの並行開発環境 大公開 / claude-code-parallel-2026-07-15
tonkotsuboy_com
12
8.7k
オブザーバビリティ、本当に活用できてる? 〜API連携×生成AIで成熟度を自動評価〜
dmmsre
1
3.6k
Featured
See All Featured
Building Adaptive Systems
keathley
44
3.1k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
830
KATA
mclloyd
PRO
35
15k
Designing Experiences People Love
moore
143
24k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
190
Six Lessons from altMBA
skipperchong
29
4.3k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
880
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Transcript
Creating a RESTful API for mobile applications Paul McMahon @pwim
My Company: My Product:
REST provides a convention for client/ server communication
The core idea in REST: everything is a resource
Example: https://community-board.herokuapp.com/communities/1 or /communities/1
Four methods: GET, POST, PUT, DELETE
5 standard actions in APIs GET /communities List communities POST
/communities Create a community GET /communities/1 Get a community PUT /communities/1 Update a community DELETE /communities/1 Delete a community
Nesting Example: GET /communities/1/posts
These actions are all you need!
The resources in your API are not the same as
in your application models
Example: Archive a community
POST /communities/1/archive
Example: Unarchive a community
DELETE /communities/1/archive
Significance of pluralization: Many communities, but only one archive per
community
Format of resource is independent of representation
So the body of a request / response could be
html, json, xml, image, etc
Practically speaking, we use json
Example { “community”: { “name”: “Tokyo iOS Meetup”, “post_count”: 5,
“members”: [ { “name”: “Paul” }, { “name”: “Matt” } ], “public”: true, }
Use HTTP Status to Indicate Status of Request
Important status codes 200 OK 201 Created 401 Not Authorized
404 Not Found 406 Not Acceptable 422 Unprocessable Entity
Authentication: Use OAuth 2.0
http://openam.forgerock.org/openam-documentation/openam-doc-source/doc/admin-guide/index/chap-oauth2.html#openam-oauth2-authz-server
API Practicalities
Version your api: /api/v1/communities
Kill Switch: Force clients to upgrade
Control Endpoint Domain: i.e, don’t use community-board.herokuapp.com in production
Don’t handcraft your json
Return complete URLs
Build your API to minimize requests for mobile client
So, what about Rails?
Anatomy of an API Controller class Api::V1::CommunitiesController respond_to :json def
index @communities = Community.all respond_with @communities end end
Generating JSON user.as_json(include: { posts: { include: { comments: {
only: :body } }, only: :title } })
RABL # app/views/posts/index.rabl collection @posts attributes :id, :title, :subject child(:user)
{ attributes :full_name } node(:read) { |post| post.read_by?(@user) } [{ "post" : { "id" : 5, title: "...", subject: "...", "user" : { full_name : "..." }, "read" : true } }]
ActiveModel Serializers class PostSerializer < ActiveModel::Serializer attributes :id, :title, :body
has_many :comments end class CommentSerializer < ActiveModel::Serializer attributes :id, :text end # /posts/1 { “post” : { “id”: 1, “title”: “Sample”, “body”: “Sample Body”, “comments”: [ {“id”: 1, “text”: “comment 1”}}, {“id”: 2, “text”: “comment 2”}] }
OAuth2 with Doorkeeper class Api::V1::CommunitiesController respond_to :json doorkeeper_for :index def
index @communities = Community.all respond_with @communities end end