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
外部APIとうまく付き合う
Search
makinoshi
February 17, 2018
Programming
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
外部APIとうまく付き合う
Clojureを使って外部APIを使うコードを設計する、書く方法について
makinoshi
February 17, 2018
Other Decks in Programming
See All in Programming
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
610
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
740
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
180
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
3.8k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
The Pragmatic Product Professional
lauravandoore
37
7.5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
990
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
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Ͱ͋Δ͜ͱࣗମ֎͔ ΒӅ͢ˠޙʑ؆୯ʹมߋͰ͖Δ • Γྫ֎Ͱͳ͘σʔλͱͯ͠ѻ͍͘͢
͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ͥͻ͝ҙݟΛԼ͍͞ɻ