Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Creating a RESTful API for mobile applications
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Paul McMahon
March 25, 2013
Technology
320
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
Transcript
36 slides
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
More Decks by Paul McMahon
See All by Paul McMahon
Why Ember.js?
pwim
0
1.2k
JSON API
pwim
0
160
A developer's perspective on entrepreneurship
pwim
1
410
Using GitHub to get a better job
pwim
11
2.3k
Using Analytics to Improve UX
pwim
0
3.5k
Event Organizers Co-Edo edition
pwim
0
2.9k
勉強会を開催する大まかな流れ
pwim
2
10k
Creating International Communities in Japan
pwim
0
240
英語でコミットを書こう
pwim
52
28k
Other Decks in Technology
See All in Technology
AWS Client VPNの設定でハマったポイントとその過程での気づき
amarelo_n24
1
360
小さなエージェントから始めてみよう!実践コンテキストエンジニアリング
iwamot
PRO
0
130
「個社」ではなく「業界」の課題を解く AI 対話開発 ー 価値を広げる設計と、価値を守るエンジニアリング ー
ivry_presentationmaterials
3
520
【Oracle AI SPOTLIGHT ウェビナー】【特別開催:日本語で解説!】Oracle AI World 2026 最新情報フィードバック
oracle4engineer
PRO
1
280
アラートを見直していたら営業組織への理解にちょっとだけ繋がった話
z63d
1
210
PHPで家庭用ゲーム機の専用コントローラーをMIDIデバイスとして扱ってみる
wind111
0
130
人の努力に頼らないセキュリティをエンジニアリングする在り方 / An approach to engineering security that does not rely on human effort
carta_engineering
0
210
Claude Securityを使ってみた / claude-security-claude-code-meetup-nagoya
tnir
0
140
Sonnetだけで業務はまわる?
kintotechdev
1
140
常時稼働エージェントの作り方(Claude公式ブログを資料化)
minorun365
PRO
16
27k
高品質と高スピードを支える品質のシフトレフトのアプローチ
goyoki
4
1.6k
RAGの改善を速く回すための評価基盤
yosukeyoshida
6
2.9k
Featured
See All Featured
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
6
940
Navigating Weather and Climate Data
rabernat
0
590
Mind Mapping
helmedeiros
1
440
Odyssey Design
rkendrick25
PRO
3
950
Everyday Curiosity
cassininazir
0
400
The SEO identity crisis: Don't let AI make you average
varn
0
630
Making the Leap to Tech Lead
cromwellryan
135
10k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
480
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.4k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
580
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
69k