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
430
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
380
Symbols and Hashes Intro
thewub
0
55
Cloud Primer
thewub
1
410
Other Decks in Technology
See All in Technology
FinOps について (ちょっと) 本気出して考えてみた
skmkzyk
0
180
難しいセキュリティ用語をわかりやすくしてみた
yuta3110
0
350
Biz職でもDifyでできる! 「触らないAIワークフロー」を実現する方法
igarashikana
3
1.2k
ソースを読むプロセスの例
sat
PRO
15
9.6k
Zephyr(RTOS)にEdge AIを組み込んでみた話
iotengineer22
1
230
ソフトウェアエンジニアの生成AI活用と、これから
lycorptech_jp
PRO
0
770
Claude Code Subagents 再入門 ~cc-sddの実装で学んだこと~
gotalab555
10
17k
私のMCPの使い方
tsubakimoto_s
0
120
AI時代の開発を加速する組織づくり - ブログでは書けなかったリアル
hiro8ma
1
190
AIエージェント入門 〜基礎からMCP・A2Aまで〜
shukob
0
130
JSConf JPのwebsiteをGatsbyからNext.jsに移行した話 - Next.jsの多言語静的サイトと課題
leko
1
130
OAuthからOIDCへ ― 認可の仕組みが認証に拡張されるまで
yamatai1212
0
150
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Site-Speed That Sticks
csswizardry
13
920
What's in a price? How to price your products and services
michaelherold
246
12k
Product Roadmaps are Hard
iamctodd
PRO
55
11k
We Have a Design System, Now What?
morganepeng
53
7.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Thoughts on Productivity
jonyablonski
70
4.9k
Side Projects
sachag
455
43k
Into the Great Unknown - MozCon
thekraken
40
2.1k
How to Ace a Technical Interview
jacobian
280
24k
How STYLIGHT went responsive
nonsquared
100
5.8k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
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 謝謝