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
430
RulingOrbit
thewub
0
370
Symbols and Hashes Intro
thewub
0
39
Cloud Primer
thewub
1
380
Other Decks in Technology
See All in Technology
OpenTelemetry を使ったトレースエグザンプラーの活用 / otel-trace-exemplar
k6s4i53rx
2
630
テストプロセスで大事にしていること #jasstnano
makky_tyuyan
0
110
キャラクター制御のためのプロンプト術 for LINE Bot
uezo
0
520
Algyan イベント振り返り
linyixian
0
180
【SORACOM UG】SIM Deep Dive セキュアエレメント編
soracom
PRO
0
250
Four keys改善の取り組み事例紹介
sansantech
PRO
3
230
株式会社EventHub・エンジニア採用資料
eventhub
0
1.9k
普段有償でサポート業務をしているCSAが技術知見を無料で公開する理由
07jp27
1
630
0→1開発における技術選定において一番大切なこと
bicstone
1
320
DevOpsメトリクスとアウトカムの接続にトライ!開発プロセスを通して計測できるメトリクスの活用方法
ham0215
1
180
開発生産性向上サービスを作るFindyが自分たちで開発生産性を爆上げした組織づくりの歩み / Findy's path to boosting its own development productivity 2024-04-17
ma3tk
3
300
Databricksを活用してDELISH KITCHENのレシピレコメンドを開発した話
furu8
0
250
Featured
See All Featured
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
186
16k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
243
20k
A Tale of Four Properties
chriscoyier
150
22k
Thoughts on Productivity
jonyablonski
57
3.8k
The Art of Programming - Codeland 2020
erikaheidi
41
12k
How to name files
jennybc
64
92k
How to Ace a Technical Interview
jacobian
272
22k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
5
1.5k
Writing Fast Ruby
sferik
620
60k
Web development in the modern age
philhawksworth
202
10k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
76
41k
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 謝謝