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
Building API For The REST of Us
Search
Terry
September 26, 2016
Programming
740
8
Share
Building API For The REST of Us
Slides in RubyConf China 2016 Chengdu
Terry
September 26, 2016
More Decks by Terry
See All by Terry
RubyConf China Welcome Slides
poshboytl
1
90
Rails Girls Chengdu 2014
poshboytl
2
330
Refactoring Re-education
poshboytl
5
980
How we test our projects
poshboytl
29
1.9k
Other Decks in Programming
See All in Programming
飯MCP
yusukebe
0
440
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
240
Migration to Signals, Signal Forms, Resource API, and NgRx Signal Store @Angular Days 03/2026 Munich
manfredsteyer
PRO
0
200
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
420
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
2
470
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
480
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
170
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.5k
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
1
190
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
230
Codex の「自走力」を高める
yorifuji
0
1.3k
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
370
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
140
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
140
Unsuck your backbone
ammeep
672
58k
Believing is Seeing
oripsolob
1
100
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
The untapped power of vector embeddings
frankvandijk
2
1.6k
Test your architecture with Archunit
thirion
1
2.2k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
400
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
330
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
200
Transcript
Building API For The REST of Us — Terry Tai
About Me
Host of Teahour.FM
Creator of Railscasts-China
I’m working for My Color Way 619'4 䨅⃚
Co-founder of fengche.co
Co-team of Peatio Project
Let’s Building API
Conditions • Based on Ruby on Rails • Not a
pure API service, web is still the first-class citizen • Client builder is resource owner or ourselves
1. Stack Choice
VS
Performance
Flexibility
Level of abstraction
Community
I like Grape a little bit more!
DSL Higer Abstraction
Isolation
Michael Bleigh Grape is created by my coworker in Intridea.
He is also the creator of oauth2, omniauth, hashie, multi_json …
2. Routes & Version
In Rails
In Grape
Rails with version in header
Rails with version in header
Rails with version in header
Grape with version in header
3. Request & Params
Params Encoding application/x-www-form-urlencoded multipart/form-data application/json
Sending Params
Rails server side
Grape server side
Grape params real world example
4.Authentication
Basic Auth
None
With HTTPS?
None
Token Based Auth
Token Based Auth • Simple • A little bit more
secure than Basic Auth • Muti-tokens for authorisation
Digest Based Auth
What we use?
Open Source Exchange
Ancun
Zhiren
Signature based Authentication?
Amazon use the similar strategy
None
One request includes: • access_key • tonce • payload •
signature
Signature
payload
None
Everything Work Well until..
payload
WTF is that?
Why not use JSON?
One request includes: • access_key • tonce • payload •
signature
Strategy • Put business related data in payload as JSON
• Put authentication related data out of payload
Simpler than Amazon
5.Resource Presenter
If you use Grape
If you use Rails
The most quick way
Extract a Presenter layer
Extract a Presenter layer
Treat it as View!
Jbuilder
–DHH “Every time you use a loop in your view,
but you don’t use partial, you might be wrong.”
Jbuilder
RABL
None
It’s not View
Active Model Serializers
View A new layer VS
Two Stories ̽Terry ݏݏᦖඳԪ̾
Story 1
After user signup send him/her a welcome email
Where to put this line?
User model callback
after_create ?
after_commit on create
Send in Callback
Send in Controller
Which one is the BEST way?
I don’t know
The second solution is from Rails Guides
Story 2
Jan Xie Ex-Intridea programmer Ex-Peatio co-member Founder of Cryptape ruby-pinyin
author ruby-ethereum author My darling….
His last project in Ruby?
Python, Go
Sinatra Node
When A record created, B,C,D must be created at the
same time
A B C D
None
None
Communicating emotions
It’s become better but not BEST!
What’s the BEST way?
Jan’s solution — Service
My solution — PubSub
My solution — PubSub
My solution — PubSub
My solution — PubSub You can use Wisper gem to
do similar thing
Two hours PK…
We decide change Nothing
Maybe, there is no BEST way We need know why
people think different We need know compromise
Welcome to Chengdu ́౮᮷҅ Ӟଷԧ੪ӧమᐶጱउ૱̶͂
Spicy Food
Girls
Spicy Food
Girls
RubyConf China in Chengdu
We are hiring!
None
BTW҅I’m ́ፗካ͂
Enjoy your “one night in Chengdu”