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
750
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
97
Rails Girls Chengdu 2014
poshboytl
2
340
Refactoring Re-education
poshboytl
5
990
How we test our projects
poshboytl
29
1.9k
Other Decks in Programming
See All in Programming
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
150
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
190
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
130
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
650
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
310
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
270
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
250
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
600
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
880
T3DD26: From RAGs to Riches
martinhelmich
0
130
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
200
[GopherCon 2026] Unlocking Real-World Go Mutex Usage Patterns by Writing a Mutex Linter
palkan
0
100
Featured
See All Featured
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
710
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
490
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
410
Typedesign – Prime Four
hannesfritz
42
3.2k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
800
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Being A Developer After 40
akosma
91
590k
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”