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
Thoughts about HTTP layer
Search
Rostislav Zhuravsky
December 06, 2021
Programming
59
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Thoughts about HTTP layer
Rostislav Zhuravsky
December 06, 2021
More Decks by Rostislav Zhuravsky
See All by Rostislav Zhuravsky
Why do we need code review?
woarewe
1
98
How to become a ReCaptcha v3 expert
woarewe
0
46
The evolution of service objects
woarewe
0
51
What's "wrong" with Ruby threads?
woarewe
0
50
What's wrong with ActiveRecord?
woarewe
0
42
Other Decks in Programming
See All in Programming
Claude Team Plan導入・ガイド
tk3fftk
0
240
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.3k
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
2.8k
AIが無かった頃の素敵な出会いの話
codmoninc
1
300
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
120
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
440
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
350
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
17k
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
170
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.5k
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
450
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
120
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Agile that works and the tools we love
rasmusluckow
331
22k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
HDC tutorial
michielstock
2
760
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
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