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
Thoughts about HTTP layer
Search
Rostislav Zhuravsky
December 06, 2021
Programming
61
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Thoughts about HTTP layer
Rostislav Zhuravsky
December 06, 2021
Transcript
49 slides
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
More Decks by Rostislav Zhuravsky
See All by Rostislav Zhuravsky
Why do we need code review?
woarewe
1
110
How to become a ReCaptcha v3 expert
woarewe
0
56
The evolution of service objects
woarewe
0
60
What's "wrong" with Ruby threads?
woarewe
0
55
What's wrong with ActiveRecord?
woarewe
0
49
Other Decks in Programming
See All in Programming
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
6.2k
How SRE Grew Out of Server-Side Work and Became the Team's Own / サーバサイドから始まったSREを チームに渡すまで
maaaato
0
210
Getting Started with Vibe Coding
miccheng
0
250
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
Ruby から Emacs を操作したい
phigasui
0
390
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
2
510
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
230
数行の変更でDockerビルドを最大91%高速化~GitLab CIの実行基盤を社内40リポジトリに展開するまで~
picopico
2
270
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
150
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
300
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
470
Featured
See All Featured
How to Talk to Developers About Accessibility
jct
2
630
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
830
The Cult of Friendly URLs
andyhume
79
7.1k
Design in an AI World
tapps
1
400
Speed Design
sergeychernyshev
33
2.3k
Fireside Chat
paigeccino
43
4.1k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
850
How to build a perfect <img>
jonoalderson
1
6.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
990
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
380