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
20250903_1つのAWSアカウントに複数システムがある環境におけるアクセス制御をABACで実現.pdf
yhana
2
420
Skrub: machine-learning with dataframes
gaelvaroquaux
0
120
AI駆動開発に向けた新しいエンジニアマインドセット
kazue
0
260
なぜSaaSがMCPサーバーをサービス提供するのか?
sansantech
PRO
8
2.5k
「何となくテストする」を卒業するためにプロダクトが動く仕組みを理解しよう
kawabeaver
0
220
[RSJ25] Feasible RAG: Hierarchical Multimodal Retrieval with Feasibility-Aware Embodied Memory for Mobile Manipulation
keio_smilab
PRO
0
110
MCPで変わる Amebaデザインシステム「Spindle」の開発
spindle
PRO
3
2.9k
5年目から始める Vue3 サイト改善 #frontendo
tacck
PRO
3
200
allow_retry と Arel.sql / allow_retry and Arel.sql
euglena1215
1
160
エラーとアクセシビリティ
schktjm
0
1k
ヘブンバーンズレッドにおける、世界観を活かしたミニゲーム企画の作り方
gree_tech
PRO
0
570
DDD集約とサービスコンテキスト境界との関係性
pandayumi
2
260
Featured
See All Featured
Building Applications with DynamoDB
mza
96
6.6k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
The Pragmatic Product Professional
lauravandoore
36
6.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
A designer walks into a library…
pauljervisheath
207
24k
Agile that works and the tools we love
rasmusluckow
330
21k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
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 謝謝