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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Saurabh Bhatia
February 22, 2014
Technology
450
0
Share
Rails API
API only applications with Rails API
Saurabh Bhatia
February 22, 2014
More Decks by Saurabh Bhatia
See All by Saurabh Bhatia
Barrister RPC
thewub
0
460
RulingOrbit
thewub
0
390
Symbols and Hashes Intro
thewub
0
64
Cloud Primer
thewub
1
420
Other Decks in Technology
See All in Technology
Agent Development Kit (ADK)で学ぶ実践Context Engineeringと社内での応用例
lycorptech_jp
PRO
0
320
Claude Code で使える DuckDB Skills を試してみた / DuckDB Skills and Claude Code
masahirokawahara
2
2.1k
A Harness for Behaviour: how to get AI to generate code that does what we intend, or "TDD in the age of AI"
xpmatteo
0
260
LT準備のToilを削減 〜決定論×確率論のスライド生成CLI〜
shukob
0
120
AI Agent に“攻略本”を渡したら、150フォームの移行が回り始めた話/登壇資料(高橋 悟生)
hacobu
PRO
1
350
ECSのTerraformモジュールにコントリビュートした話
harukasakihara
1
330
基礎から解説!Icebergで紐解くSnowflake×Databricks連携の現在地
cm_yasuhara
0
210
権限管理設計を完全に理解した
rsugi
1
180
JaSSTに関わることで変わった人生観 #jasstnano
makky_tyuyan
0
180
その英語学習、AWSで代替できませんか?
suzutatsu
1
210
"スキルファースト"で作る、AIの自走環境
subroh0508
1
690
ルール・ロール・ツールを創る / Creating Rules, Roles and Tools
ks91
PRO
0
150
Featured
See All Featured
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
550
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
560
Building AI with AI
inesmontani
PRO
1
1k
Exploring anti-patterns in Rails
aemeredith
3
360
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
140
Are puppies a ranking factor?
jonoalderson
1
3.4k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Amusing Abliteration
ianozsvald
1
170
Optimizing for Happiness
mojombo
378
71k
How STYLIGHT went responsive
nonsquared
100
6.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
A Tale of Four Properties
chriscoyier
163
24k
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 謝謝