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
Rails API
Search
Saurabh Bhatia
February 22, 2014
Technology
0
440
Rails API
API only applications with Rails API
Saurabh Bhatia
February 22, 2014
Tweet
Share
More Decks by Saurabh Bhatia
See All by Saurabh Bhatia
Barrister RPC
thewub
0
450
RulingOrbit
thewub
0
390
Symbols and Hashes Intro
thewub
0
59
Cloud Primer
thewub
1
410
Other Decks in Technology
See All in Technology
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
130
Bill One急成長の舞台裏 開発組織が直面した失敗と教訓
sansantech
PRO
1
270
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
390
Agile Leadership Summit Keynote 2026
m_seki
1
310
オープンウェイトのLLMリランカーを契約書で評価する / searchtechjp
sansan_randd
3
650
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.2k
制約が導く迷わない設計 〜 信頼性と運用性を両立するマイナンバー管理システムの実践 〜
bwkw
2
850
外部キー制約の知っておいて欲しいこと - RDBMSを正しく使うために必要なこと / FOREIGN KEY Night
soudai
PRO
11
4.6k
ファインディの横断SREがTakumi byGMOと取り組む、セキュリティと開発スピードの両立
rvirus0817
1
1.1k
なぜ今、コスト最適化(倹約)が必要なのか? ~AWSでのコスト最適化の進め方「目的編」~
htan
1
110
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
260
プロダクト成長を支える開発基盤とスケールに伴う課題
yuu26
3
1.2k
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
110
Test your architecture with Archunit
thirion
1
2.1k
How to make the Groovebox
asonas
2
1.9k
Prompt Engineering for Job Search
mfonobong
0
160
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Into the Great Unknown - MozCon
thekraken
40
2.2k
WCS-LA-2024
lcolladotor
0
440
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
55
The Pragmatic Product Professional
lauravandoore
37
7.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Transcript
API Only Applications with rails-api Saurabh Bhatia http://fedible.org
what? $ gem install rails-api Rails minus some middleware stack,
actionpack modules and template generation.
why? • Lightweight • Fast • API only application –
backend for mobile app, web application is just another client (e.g. html, angular.js ) to a json api.
Generating a new app $ rails-api new notesapp
No views
rails-api controller app/controllers/application_controller.rb class ApplicationController < ActionController::API end
controller actions def index @posts = Post.all render json: @posts
end • rails-api uses render instead of respond methods. • Let's see how to include those.
extending controller class ApplicationController < ActionController::API include ActionController::MimeResponds include ActionController::ImplicitRender
end • MimeResponds and Implicit render provide support for respond_to, respond_with.
middleware
extending middleware $config/application.rb require File.expand_path('../boot', __FILE__) require 'rails/all'. Bundler.require(:default, Rails.env)
module Notesapp class Application < Rails::Application config.middleware.use ActionDispatch::Flash end end
extended
serializers • gem "active_model_serializers" • $rails g serialzer post •
$ ls assets controllers mailers models serializers app$ cd serializers/ app/serializers$ ls post_serializer.rb
serialzers class PostSerializer < ActiveModel::Serializer attributes :title, :body end •
JSON Response {"posts": [{"id":1,"title":"First Post","body":"Test"}, {"id":2,"title":"Second Post","body":"Another Test"}] }
Shameless Plug : Rails 4 application development
Thank you 謝謝