Skip to content

chore: Improve network code#49

Closed
tevincent wants to merge 7 commits intomainfrom
improve-network-code
Closed

chore: Improve network code#49
tevincent wants to merge 7 commits intomainfrom
improve-network-code

Conversation

@tevincent
Copy link
Contributor

@tevincent tevincent commented Mar 6, 2026

depends on #41

@tevincent tevincent force-pushed the generate-crypto-objects branch from 929413e to d686fe8 Compare March 12, 2026 08:45
@tevincent tevincent force-pushed the improve-network-code branch from 7fa7db5 to 538b974 Compare March 12, 2026 08:46
@tevincent tevincent force-pushed the generate-crypto-objects branch from d96a47e to 56913a4 Compare March 13, 2026 08:01
Base automatically changed from generate-crypto-objects to main March 13, 2026 08:34
@github-actions
Copy link

This PR/issue depends on:

@tevincent tevincent force-pushed the improve-network-code branch from 49f6d15 to d85419f Compare March 13, 2026 08:34
@github-actions
Copy link

The refactoring improves the networking architecture by centralizing environment configuration in ApiClientProvider using Ktor's defaultRequest plugin, eliminating the redundant BaseRequest abstraction and simplifying repository constructors. The migration to direct HttpClient usage with extension functions provides cleaner request syntax, though the deletePasskey method inconsistently uses a hardcoded URL path instead of ApiRoutes constants like other endpoints.

#ai-review-summary

// When you don't use AuthenticatorInjection, you don't have an userAgent, so we're currently setting a default value.
// See later how to improve it.
private val userAgent: String = "Ktor client",
class ApiClientProvider constructor(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class visibility changed from 'internal' to 'public' - confirm this exposure to public API is intentional.

Suggested change
class ApiClientProvider constructor(
internal class ApiClientProvider constructor(

#ai-review-inline

coerceInputValues = true // Use default values if not recognized (used for enums).
ignoreUnknownKeys = true // Don't break if keys are added.
@OptIn(ExperimentalSerializationApi::class)
decodeEnumsCaseInsensitive = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing 'useAlternativeNames = false' setting from previous JSON configuration, which may change serialization behavior for classes with @SerialName annotations.

Suggested change
decodeEnumsCaseInsensitive = true
decodeEnumsCaseInsensitive = true
useAlternativeNames = false

#ai-review-inline

crashReport = crashReport,
)

val json = Json {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class-level 'json' property is no longer used by the HTTP client configuration, creating duplicate configuration and maintenance confusion.

#ai-review-inline

// When you don't use AuthenticatorInjection, you don't have an userAgent, so we're currently setting a default value.
// See later how to improve it.
private val userAgent: String = "Ktor client",
class ApiClientProvider constructor(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal of HttpClientEngine parameter reduces testability by preventing injection of mock/test engines.

#ai-review-inline


suspend fun deletePasskey(token: String, passkeyId: String) {
return delete(createUrl("users/me/passkeys/$passkeyId"), appendHeaders = {
httpClient.delete(Url("users/me/passkeys/$passkeyId")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent response handling: 'deletePasskey' does not decode the response or handle errors like other methods (get/challenge/verify).

Suggested change
httpClient.delete(Url("users/me/passkeys/$passkeyId")) {
httpClient.delete(Url("users/me/passkeys/$passkeyId")) {
addAuthenticationHeader(token)
}.decode<Unit>()

#ai-review-inline

@tevincent tevincent closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant