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
100
How to become a ReCaptcha v3 expert
woarewe
0
49
The evolution of service objects
woarewe
0
55
What's "wrong" with Ruby threads?
woarewe
0
52
What's wrong with ActiveRecord?
woarewe
0
42
Other Decks in Programming
See All in Programming
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
180
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
2
110
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
260
信頼性の目標を誰も求めてない
shubox
0
490
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
340
Foundry Localでエージェント開発
seosoft
0
140
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.3k
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
840
バグを直したら useEffect が消えた
colorful12
3
840
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.9k
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
670
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
We Have a Design System, Now What?
morganepeng
55
8.3k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
Side Projects
sachag
455
43k
Producing Creativity
orderedlist
PRO
348
41k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
510
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
490
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
450
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