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
外部APIとうまく付き合う
Search
makinoshi
February 17, 2018
Programming
0
360
外部APIとうまく付き合う
Clojureを使って外部APIを使うコードを設計する、書く方法について
makinoshi
February 17, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
410
AIコーディングエージェント(Manus)
kondai24
0
220
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
3.1k
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
220
JETLS.jl ─ A New Language Server for Julia
abap34
2
460
Vibe codingでおすすめの言語と開発手法
uyuki234
0
130
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
310
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
200
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
460
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
120
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
390
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
270
Featured
See All Featured
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
410
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
270
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
51
The World Runs on Bad Software
bkeepers
PRO
72
12k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
260
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
70
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
0
31
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
So, you think you're a good person
axbom
PRO
0
1.8k
Transcript
֎෦"1*ͱ ͏·͖͘߹͏ 2018-02-11 clj-ebisu #2 @makinoshi
Me • αΠϘζελʔτΞοϓεגࣜձࣾ • Like: C++(11~), PostgreSQL(SQL), Clojure, Emacs(Spacemacs), MS
Sculpt Ergonomic Keyboard • Hobby: ϚϯΨ,͓ञ • ࠷ۙͷΠνΦγ: cljr-create-fn-from-example
ΞδΣϯμ • (֎෦)APIʹΞΫηε͢Δ෦ΛͲ͏࡞Δ͔ • ೖྗ͢ΔσʔλߏΛͲ͏ͭ͘Δ͔ • ΧϓηϧԽ͞Εͨ෦ॲཧΛͭ͘Δ • ݁ՌΛද͢σʔλߏ
ೖྗ͢ΔσʔλߏΛ࡞Δ
ྫ) SendGridͷAPI {:headers {"Authorization" "Bearer ...."} :content-type :json :form-params {:subject
"໊݅" :content [{:type "text/plain" :value "ຊจ"}] :from {:name "MyService" :email "
[email protected]
"} :personalizations [{:to [{:email "
[email protected]
" :name "a͞Μ"} {:email "
[email protected]
" :name "a͞Μ"}] :custom_args {:id "1"}} {:to [{:email "
[email protected]
" :name “b͞Μ"}] :custom_args {:id “2"}}]}} • ͜ͷߏΛҙࣝͨ͠ίʔυॻ͖ͨ͘ͳ͍
Builderύλʔϯ • ֤ϝιουͰҾΛνΣοΫͭͭ͠σʔλཷ ΊࠐΉ • buildϝιουͰ͑ΔɺνΣοΫ͢Δ • ೖग़ྗܗࣜͷมߋΛ෦ͰٵऩͰ͖ΔˠAPIͷ มߋ͏APIࣗମͷมߋ༰қʹͳΔ
࣮ྫ (-> (mail/builder something-component) (mail/with-subject "໊݅") (mail/with-content "ຊจ") (mail/with-recipients [{:email
"
[email protected]
" :to-name "a͞Μ" :id 1 :callback “/app/path/1”} {:email "
[email protected]
" :to-name "b͞Μ" :id 2 :callback “/app/path/2”}]) mail/build) • AWS SDK for Javaͷ࣮͕BuilderύλʔϯΛ ͱ্ͯखʹ͍ͬͯΔͱࢥ͍·͢
෦ॲཧΛΧϓηϧԽ͢Δ
͏ଆʹ࿙Βͨ͘͠ͳ͍ • ͏ϥΠϒϥϦͷڍಈ • ྫ֎͕ൃੜ͢Δঢ়گͷࠩҟɺΓͷࠩҟ(map, promise, etc..) • ࣮ߦ •
rate limit • ಉ࣌ଓ • ϦτϥΠ • ෳͷϦΫΤετ୯ҰϦΫΤετͷγʔέϯεͱͯ͠ѻ͍͍ͨ
diehardͱڞʹ • https://github.com/sunng87/diehard • ઃఆϕʔεͰɺretry/circuit breaker/rate limitterΛ؆୯ʹ࣮Ͱ͖Δ • JavaͷϥΠϒϥϦɺnet.jodah/failsafeͷϥο ύ
࣮ྫ (diehard.core/defratelimiter rl {:rate 100}) ; per sec (clj-http.client/with-connection-pool {:timeout
10 :insecure? false :default-per-route 100} (->> coll (map #(future (diehard.core/with-retry {:retry-if (fn [resp exp] (or (>= (:status resp) 500) (instance? IOException exp))) :max-retries 3 :delay-ms 1000} (diehard.core/with-rate-limiter rl (api/call endpoint %))))) (map deref) doll)) • ΊͪΌͪ͘Ό؆୯ • ͬͱهड़ྔগͳ͘ఆٛ͢Δํ๏υΩϡϝϯτʹ͋Γ·͢
Γͷදݱ
ओͳΤϥʔॲཧ • ѻ͍͍͢Γ • ୯ͳΔσʔλ • Τϥʔ͔Ͳ͏͔ఆ͍͢͠ • Τϥʔʹͳͬͨͱ͖ͷҾΛͦͷ··औΓग़ͤΔ •
ѻ͍ʹ͍͘Γ • ྫ֎͕͛ΒΕͨΓɺ͛ΒΕͳ͔ͬͨΓ • ֎෦ͷϥΠϒϥϦͰఆٛ͞Εͨܕ • promise(ಛʹ֎෦ϥΠϒϥϦͷ) • ඇಉظ͕͍͍͔Ͳ͏͔ݺͼग़͠ଆͷࣄ • => GolangελΠϧ or ಠࣗఆٛͷEitherͷͲͪΒ͔͕Αͦ͞͏
࣮ࡍʹ྆ํͬͯΈͨ݁Ռ • GolangελΠϧͷํ͕ॻ͍ͯͯϛε͕গͳͦ͞͏ʹײ͍ͯ͡· ͢ • ѻ͍͘͢ɺγϯϓϧʹॻ͚Δ • (group-by #(-> %
second some?) results) (try (let [resp (clj-http.client/post endpoint params)] [{:resp resp resp :params params} nil]) (catch clojure.lang.ExceptionInfo e [{:params params} (ex-data e)]) (catch java.io.IOException e [{:params params} e]))
·ͱΊ • ClojureͰσʔλ࡞ͷநԽʹBuilder ཱͭ • ϥΠϒϥϦͷڍಈAPIͰ͋Δ͜ͱࣗମ֎͔ ΒӅ͢ˠޙʑ؆୯ʹมߋͰ͖Δ • Γྫ֎Ͱͳ͘σʔλͱͯ͠ѻ͍͘͢
͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ͥͻ͝ҙݟΛԼ͍͞ɻ