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
AIのReact習熟度を測る
uhyo
2
680
WebGIS AI Agentの紹介
_shimizu
0
560
SteampipeとExcel Power QueryでAWS構成定義書の作成を自動化する
jhashimoto
0
180
【2026年版】 ベクトル検索とEmbedding最前線
mocobeta
24
7.6k
コミュニティの有益性 ~JAWS Days 2026 での体験を通して~ / The Benefits of a Community ~Through My Experience at JAWS Days 2026~
seike460
PRO
0
270
Microsoft のサポートとフィードバック総まとめ
murachiakira
PRO
0
110
飲食店もAIで。レジ締めやハンディシステムをつくってる話 / Using AI for restaurant management
vtryo
0
180
OTel × Datadog で 「AI活用」を計測し、改善に繋げる
shihochan
2
640
感情と身体を置き去りにしない、エンジニアの生きのこり方 ──いまから、ここから「自分の状態」を扱うという選択
saorimurooka
0
340
現場のトークンマネジメント
dak2
1
190
BPaaSで進むAIオペレーションの現在地 AI実装が効く領域とスケーラビリティの選定と実装
kentarofujii
0
190
IaC コードを資産へ:AWS CDK 社内ライブラリと横断展開 / aws-summit-japan-2026
gotok365
10
1.6k
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
7k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
360
Six Lessons from altMBA
skipperchong
29
4.3k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
230
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Typedesign – Prime Four
hannesfritz
42
3.1k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
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