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
360
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
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Prompt Engineering for Job Search
mfonobong
0
460
Bash Introduction
62gerente
615
220k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
450
WENDY [Excerpt]
tessaabrams
14
40k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.3k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
710
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
290
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
270
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
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のコルーチンを ネイティブにサポート
果たして実用に値するのか?
本日のコードスニペットはこちらに置いてあります 📦