Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Thoughts about HTTP layer
Search
Rostislav Zhuravsky
December 06, 2021
Programming
0
56
Thoughts about HTTP layer
Rostislav Zhuravsky
December 06, 2021
Tweet
Share
More Decks by Rostislav Zhuravsky
See All by Rostislav Zhuravsky
Why do we need code review?
woarewe
1
93
How to become a ReCaptcha v3 expert
woarewe
0
38
The evolution of service objects
woarewe
0
42
What's "wrong" with Ruby threads?
woarewe
0
40
What's wrong with ActiveRecord?
woarewe
0
35
Other Decks in Programming
See All in Programming
How Software Deployment tools have changed in the past 20 years
geshan
0
29k
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
120
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
320
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
120
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
440
Cap'n Webについて
yusukebe
0
130
20251127_ぼっちのための懇親会対策会議
kokamoto01_metaps
2
420
認証・認可の基本を学ぼう後編
kouyuume
0
180
React Native New Architecture 移行実践報告
taminif
1
150
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
110
dotfiles 式年遷宮 令和最新版
masawada
1
750
FluorTracer / RayTracingCamp11
kugimasa
0
220
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
2.2k
Become a Pro
speakerdeck
PRO
31
5.7k
KATA
mclloyd
PRO
32
15k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Documentation Writing (for coders)
carmenintech
76
5.2k
We Have a Design System, Now What?
morganepeng
54
7.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Navigating Team Friction
lara
191
16k
Context Engineering - Making Every Token Count
addyosmani
9
500
Visualization
eitanlees
150
16k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Transcript
How we have been taming Faraday
None
My first task
We use Faraday
What else can be used for HTTP calls?
More detailed overview
My experience
HTTParty
Faraday using class methods
Faraday using connection
Get back to the task
How bad requests are handled
The problematic code
If you wouldn’t approve it, please, raise a hand
What problems have we got?
Adding a new request requires remembering about a lot of
things: • Which statuses can be returned? • What errors can be thrown? • How to handle the errors? • What to do with a failed request? Retries?
Our codebase is heavily glued to Faraday • What if
Faraday API would be changed? • What if we would want to change the library? • What if we would need to fix/extend current implementation? • How to test it? Should we stub HTTP requests or mock objects?
Everything we’re trying to achieve is to get some data
HTTP is only an implementation detail
Transportation layer Business logic Gem API
Isolate all transportation details
Business logic Transportation layer Gem API
Isolate your dependencies
Business logic Transportation layer Library wrapper Gem API
Situation on the project Business logic Transportation layer Gem API
Our plan was • Look through all the places where
Faraday is used • Collect all the features we need to implement in our wrapper • Replace step by step Faraday with our library using feature toggles
Features we need to support • Retries • Follow redirects
• Raise an error on failure • Notify to Bugsnag • Parallel execution • Configure timeouts • Different request/response data format
An example of serial requests
An example of concurrent requests
How have we implemented that?
Faraday has a great feature: middleware
Faraday::Response::RaiseError
Retries
The hardest part was concurrent mode
We use Typhoeus for concurrent requests
Usage
Solution #1: Faraday supports Typhoeus adapter
None
Why is that problem for us?
Solution #2. Gem parallel
Final version
How to test an HTTP client?
None
Mock requests
Webmock
More about the topic
Summary • Write a high-level abstractions which correspond to actual
business rules • Isolate dependencies on gems/libs • Explicit is better than implicit a.k.a keep everything you can under your control • Write tests
Useful links • https://github.com/lostisland/faraday/issues/1310 • https://thoughtbot.com/upcase/videos/testing-interaction-with-3rd-party-apis • https://gist.github.com/woarewe/543a1275382941ffbb87324d2b302100 • https://gist.github.com/woarewe/81e2f8d181f99511985f91926d7f2f54
• https://gist.github.com/woarewe/16a33e3eecbd7e2af9622afb2898db28 •
Thanks