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
KMPでもRetrofitっぽくAPI通信がしたい!
Search
Hina Nakahira
July 05, 2024
390
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
KMPでもRetrofitっぽくAPI通信がしたい!
Hina Nakahira
July 05, 2024
More Decks by Hina Nakahira
See All by Hina Nakahira
【Otegami】「月経期間のパートナーとのすれ違いを軽減する」
hinalin
0
1.5k
【metimo】「『似合う』を楽しもう。」
hinalin
0
1.5k
【KC3 Shinkan Fes 2024】モバイルアプリ開発 - ひなりん
hinalin
0
130
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
The Limits of Empathy - UXLibs8
cassininazir
2
720
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
560
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
470
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
880
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
350
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
700
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Transcript
KMPでもRetrofitっぽく API通信がしたい! ひなりん (@soleil_colza_)
ひなりん (@soleil_colza_) STORES株式会社ブランドアプリグループ Androidエンジニアインターン 🐣 趣味は車とTrending Repositories の徘徊 学生・社会人混合 Androidエンジニアコミュニティ
NID.kt 運営
もくじ KMPのうまみ、つらみ 1 KMPにおけるAPI通信 2 Ktorfitの紹介 3
None
ドメイン層まで、あるいはView未満全ての共通化 → ネイティブの使用感を残しつつ、開発を高速化できる KMPのうまみ サーバーとフロントエンドでコードを共有できる → OSS としても, 単一のコードベースで 様々な環境に対応できるのは非常に魅力的。
KMPのつらみ Objective-Cで出てくる(今年Swift対応するよ!) 💊 touchlab/SKIE ドキュメントがまだまだ未熟 iOSエンジニアを宥める必要がある
ライブラリが....!ないっっっっ....!!!! KMPのつらみ あったと思ったら特定の実行環境は対応していなかったり androidx Retrofit これはチャンス。 黎明期の今、自作ライブラリで次のスタンダードを作ろう。
KMP対応ライブラリを まとめたリポジトリがあります 🙆♀️
AAkira/Kotlin-Multiplatform-Libraries
AAkira/Kotlin-Multiplatform-Libraries
Retrofit はKMP をサポートしていない。 Ktorの出番!!
Ktor/Retrofitの記法のちがい 1. 初期化と設定 HttpClientを直接初期化し、 必要なプラグイン (e.g. ContentNegotiation)を インストールして設定。
Ktor/Retrofitの記法のちがい 1. 初期化と設定 Retrofit.Builderを使用してインスタンスを作成し、 ベースURLとコンバーター(e.g. GsonConverterFactory)を設定。
2. APIインターフェースの定義 Ktor/Retrofitの記法のちがい APIインターフェースの定義は必要なく、直接HTTPリクエストを作成
2. APIインターフェースの定義 Ktor/Retrofitの記法のちがい インターフェースを使用してリクエストメソッドを定義
3. リクエストの実行 Ktor/Retrofitの記法のちがい コルーチンを使用して非同期リクエストを実行(いいね! 🙆♀️)
3. リクエストの実行 Ktor/Retrofitの記法のちがい enqueueメソッドを使用して非同期リクエストを実行
Ktorfitの何が嬉しい?
Retrofit風のInterface定義 1. Ktor/Retrofitのいいとこどりができる アノテーションベースのインターフェースを使用してAPIを定義できる。 Retrofitに慣れた開発者にとっては直感的で嬉しい。
非同期処理がより簡潔に記述できる。 Ktorのエコシステムに統合されているため、 Retrofitらしさを出しながら Ktorのうまみを活かしている。 2. Kotlinのコルーチンを ネイティブにサポート
果たして実用に値するのか?
本日のコードスニペットはこちらに置いてあります 📦