Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
760
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
Transcript
115 slides
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”
More Decks by Terry
See All by Terry
RubyConf China Welcome Slides
poshboytl
1
100
Rails Girls Chengdu 2014
poshboytl
2
340
Refactoring Re-education
poshboytl
5
1k
How we test our projects
poshboytl
29
2k
Other Decks in Programming
See All in Programming
From Java 8-11 to Java 21-27 — Benefits, Challenges, and a Practical Migration Path
x5gtrn
PRO
0
100
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
310
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
4
4.5k
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
240
自宅サーバはどこまで再現できるのか - Proxmox VE上のVM環境をIaCとバックアップで戻してみた
youto
0
260
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
160
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
210
LLM 101
dalinaum
0
490
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
150
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
150
AI-Powered Domain-Driven Design
ziobrando
0
450
あなたはMCPの機能を、まだ知らない。
4geru
1
140
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
7.1k
Embracing the Ebb and Flow
colly
88
5.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
A designer walks into a library…
pauljervisheath
211
25k
Deep Space Network (abreviated)
tonyrice
0
420
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
580
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
810
GraphQLとの向き合い方2022年版
quramy
50
15k
How to Ace a Technical Interview
jacobian
280
24k
Thoughts on Productivity
jonyablonski
76
5.5k