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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
96
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
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.1k
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
初めてのKubernetes 本番運用でハマった話
oku053
0
130
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
4.3k
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
160
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
120
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
210
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
150
Performance Engineering for Everyone
elenatanasoiu
0
270
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
0
160
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
580
Featured
See All Featured
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
330
Prompt Engineering for Job Search
mfonobong
0
380
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Being A Developer After 40
akosma
91
590k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
[SF Ruby Conf 2025] Rails X
palkan
2
1.2k
Paper Plane (Part 1)
katiecoart
PRO
1
9.7k
New Earth Scene 8
popppiees
3
2.4k
Chasing Engaging Ingredients in Design
codingconduct
0
240
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
The Language of Interfaces
destraynor
162
27k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
800
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”