Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rails API
Search
Saurabh Bhatia
February 22, 2014
Technology
0
440
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
390
Symbols and Hashes Intro
thewub
0
56
Cloud Primer
thewub
1
410
Other Decks in Technology
See All in Technology
業務のトイルをバスターせよ 〜AI時代の生存戦略〜
staka121
PRO
2
180
AWS CLIの新しい認証情報設定方法aws loginコマンドの実態
wkm2
6
740
20251209_WAKECareer_生成AIを活用した設計・開発プロセス
syobochim
7
1.5k
エンジニアリングをやめたくないので問い続ける
estie
2
1.2k
.NET 10の概要
tomokusaba
0
110
SREには開発組織全体で向き合う
koh_naga
0
160
5分で知るMicrosoft Ignite
taiponrock
PRO
0
360
評価駆動開発で不確実性を制御する - MLflow 3が支えるエージェント開発
databricksjapan
1
180
CARTAのAI CoE が挑む「事業を進化させる AI エンジニアリング」 / carta ai coe evolution business ai engineering
carta_engineering
0
1.3k
[JAWS-UG 横浜支部 #91]DevOps Agent vs CloudWatch Investigations -比較と実践-
sh_fk2
2
260
今からでも間に合う!速習Devin入門とその活用方法
ismk
1
700
LLM-Readyなデータ基盤を高速に構築するためのアジャイルデータモデリングの実例
kashira
0
250
Featured
See All Featured
Balancing Empowerment & Direction
lara
5
800
BBQ
matthewcrist
89
9.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.3k
Facilitating Awesome Meetings
lara
57
6.7k
Site-Speed That Sticks
csswizardry
13
1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Bash Introduction
62gerente
615
210k
What's in a price? How to price your products and services
michaelherold
246
13k
A Tale of Four Properties
chriscoyier
162
23k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
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 謝謝