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
61
Cloud Primer
thewub
1
410
Other Decks in Technology
See All in Technology
推し活エージェント
yuntan_t
1
700
GitHub Advanced Security × Defender for Cloudで開発とSecOpsのサイロを超える: コードとクラウドをつなぐ、開発プラットフォームのセキュリティ
yuriemori
1
120
FlutterでPiP再生を実装した話
s9a17
0
250
「決め方」の渡し方 / How to hand over the "decision-making process"
pauli
4
350
Data Enabling Team立ち上げました
sansantech
PRO
0
240
互換性のある(らしい)DBへの移行など考えるにあたってたいへんざっくり
sejima
PRO
0
540
制約を設計する - 非決定性との境界線 / Designing constraints
soudai
PRO
4
980
AWS DevOps Agent or Kiro の使いどころを考える_20260402
masakiokuda
0
150
Databricks Appsで実現する社内向けAIアプリ開発の効率化
r_miura
0
250
Tour of Agent Protocols: MCP, A2A, AG-UI, A2UI with ADK
meteatamel
0
200
OpenClawでPM業務を自動化
knishioka
2
370
Move Fast and Break Things: 10 in 20
ramimac
0
120
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
Automating Front-end Workflow
addyosmani
1370
200k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
240
Navigating Weather and Climate Data
rabernat
0
160
Testing 201, or: Great Expectations
jmmastey
46
8.1k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
140
The Art of Programming - Codeland 2020
erikaheidi
57
14k
How to build a perfect <img>
jonoalderson
1
5.3k
Bash Introduction
62gerente
615
210k
Mind Mapping
helmedeiros
PRO
1
140
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
780
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
250
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 謝謝