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
400
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
KMPでもRetrofitっぽくAPI通信がしたい!
Hina Nakahira
July 05, 2024
Transcript
22 slides
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のコルーチンを ネイティブにサポート
果たして実用に値するのか?
本日のコードスニペットはこちらに置いてあります 📦
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
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
69k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
640
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
480
A Modern Web Designer's Workflow
chriscoyier
699
190k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
750
Faster Mobile Websites
deanohume
310
32k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
sira's awesome portfolio website redesign presentation
elsirapls
0
510
Navigating Team Friction
lara
192
16k