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
440
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
450
RulingOrbit
thewub
0
390
Symbols and Hashes Intro
thewub
0
62
Cloud Primer
thewub
1
410
Other Decks in Technology
See All in Technology
Hacobu Tech Deck
hacobu
PRO
0
120
AI時代 に増える データ活用先
takahal
0
310
生成AIが変える SaaS の競争原理と弁護士ドットコムのプロダクト戦略
bengo4com
1
2.2k
今年注目する!データ分析プラットフォームでのAIの活用
nayuts
0
150
社内エンジニア勉強会の醍醐味と苦しみ/tamadev
nishiuma
0
230
ハーネスエンジニアリングの概要と設計思想
sergicalsix
9
5.2k
[OAWTT26][THR1028] Oracle AI Database 26ai へのアップグレード:ベストプラクティスと最新情報
oracle4engineer
PRO
1
110
扱える不確実性を増やしていく - スタートアップEMが考える「任せ方」
kadoppe
0
320
需要創出(Chatwork)×供給(BPaaS) フライホイールとMoat 実行能力の最適配置とAI戦略
kubell_hr
0
710
AI: Making Admin and Users, Lives Better
kbmsg
0
110
バイブコーディングで3倍早く⚪⚪を作ってみた
samakada
0
110
[OpsJAWS 40]リリースしたら終わり、じゃなかった。セキュリティ空白期間をAWS Security Agentで埋める
sh_fk2
3
240
Featured
See All Featured
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
440
First, design no harm
axbom
PRO
2
1.2k
Agile that works and the tools we love
rasmusluckow
331
21k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
490
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
220
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.6k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
510
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
43k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
200
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.9k
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 謝謝