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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Terry
September 26, 2016
Programming
8
730
Building API For The REST of Us
Slides in RubyConf China 2016 Chengdu
Terry
September 26, 2016
Tweet
Share
More Decks by Terry
See All by Terry
RubyConf China Welcome Slides
poshboytl
1
89
Rails Girls Chengdu 2014
poshboytl
2
320
Refactoring Re-education
poshboytl
5
980
How we test our projects
poshboytl
29
1.9k
Other Decks in Programming
See All in Programming
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
320
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
350
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
410
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
190
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
7.9k
15年目のiOSアプリを1から作り直す技術
teakun
1
620
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
250
Claude Code Skill入門
mayahoney
0
160
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
500
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
2.1k
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
220
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.3k
Featured
See All Featured
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
The agentic SEO stack - context over prompts
schlessera
0
690
Exploring anti-patterns in Rails
aemeredith
2
290
4 Signs Your Business is Dying
shpigford
187
22k
Documentation Writing (for coders)
carmenintech
77
5.3k
Raft: Consensus for Rubyists
vanstee
141
7.3k
Context Engineering - Making Every Token Count
addyosmani
9
740
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Into the Great Unknown - MozCon
thekraken
40
2.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
First, design no harm
axbom
PRO
2
1.1k
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”