diff --git a/CHANGELOG/index.html b/CHANGELOG/index.html index 85802d0a7..1cf22542e 100644 --- a/CHANGELOG/index.html +++ b/CHANGELOG/index.html @@ -1,4 +1,4 @@ - Changelog - Ktorfit
Skip to content
🤔 Documentation issue? Report or edit

Changelog

All important changes of this project must be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

Added

Changed

  • KSP version 1.9.0-1.0.13 is now needed

Deprecated

Removed

Fixed

Security

1.4.4 - 2023-07-26

Added

Changed

  • Upgrade dependencies: Ktor 2.3.2

Deprecated

Removed

Fixed

Security

1.4.3 - 2023-07-13

Added

Changed

Deprecated

Removed

Fixed

372 Crash with Xiaomi on create Ktorfit.Builder by @princeparadoxes

Security

1.4.2 - 2023-06-25

Added

Changed

Deprecated

Removed

Fixed

323 Code generation issue for @Multipart / @FormUrlEncoded by @Ph1ll1pp

Security

1.4.1 - 2023-06-03

Added

Changed

  • Upgrade dependencies: Ktor 2.3.1

Deprecated

Removed

Fixed

236 Parsing error for list/array

Security

1.4.0 - 2023-05-27

Added

  • 85 Added a Response class that can be used as a wrapper around the API Response, the converter for it is automatically applied. thx to @vovahost, @DATL4G

e.g.

interface ExampleApi{
+ Changelog - Ktorfit       
🤔 Documentation issue? Report or edit

Changelog

All important changes of this project must be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

Added

Changed

Deprecated

Removed

Fixed

Security

1.5.0 - 2023-08-04

Added

Changed

  • KSP version 1.9.0-1.0.13 is now needed

Deprecated

Removed

Fixed

Security

1.4.4 - 2023-07-26

Added

Changed

  • Upgrade dependencies: Ktor 2.3.2

Deprecated

Removed

Fixed

Security

1.4.3 - 2023-07-13

Added

Changed

Deprecated

Removed

Fixed

372 Crash with Xiaomi on create Ktorfit.Builder by @princeparadoxes

Security

1.4.2 - 2023-06-25

Added

Changed

Deprecated

Removed

Fixed

323 Code generation issue for @Multipart / @FormUrlEncoded by @Ph1ll1pp

Security

1.4.1 - 2023-06-03

Added

Changed

  • Upgrade dependencies: Ktor 2.3.1

Deprecated

Removed

Fixed

236 Parsing error for list/array

Security

1.4.0 - 2023-05-27

Added

  • 85 Added a Response class that can be used as a wrapper around the API Response, the converter for it is automatically applied. thx to @vovahost, @DATL4G

e.g.

interface ExampleApi{
   suspend fun getUser(): Response<User>
 }
 
@@ -9,7 +9,7 @@
 }else{
   user.errorBody()
 }
-
  • Ktorfit is now using converters factories to apply the converters, similar to Retrofit see more here https://foso.github.io/Ktorfit/converters/converters/
  • TypeData now has a field “typeInfo” can be used to convert the Ktor HttpResponse body to the wanted type
  • CallConverterFactory for replacement of CallResponseConverter
  • FlowConverterFactory for replacement of FlowResponseConverter

  • Added support for targets: macosArm64, tvosArm64, tvosX64, tvosSimulatorArm64, watchosSimulatorArm64 #315

Changed

  • Upgrade dependencies: Kotlin 1.8.21

Deprecated

  • ResponseConverter, use Converter.ResponseConverter instead
  • SuspendResponseConverter, use Converter.SuspendResponseConverter instead
  • RequestConverter, use Converter.RequestParameterConverter instead
  • See also: https://foso.github.io/Ktorfit/converters/migration/

Removed

Fixed

Security

1.3.0 - 2023-05-14

Added

Changed

  • Optimized generated code, the generated code that is used for a request will now directly set the Ktor code instead of delegating it to a Ktorfit class. This will make the code easier to understand.

  • KSP version 1.0.11 is now needed

Deprecated

Removed

Fixed

[Bug]: IllegalArgumentException with Custom Http Annotation #274

Security

Bumped

KSP version to 1.0.11

1.2.0 - 2023-05-05

Added

Changed

Deprecated

Removed

Fixed

Security

Bumped

Now based on Ktor 2.3.0

1.1.0 - 2023-04-15

Added

From now on there are two versions of the ktorfit-lib.

“de.jensklingenberg.ktorfit:ktorfit-lib” will stay like before and add the platform client dependencies for the clients.

“de.jensklingenberg.ktorfit:ktorfit-lib-light” this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as “ktorfit-lib”

Changed

  • Kotlin version 1.8.20 is now needed
  • KSP version 1.8.20-1.0.10 is now needed

Deprecated

Removed

Fixed

Security

Bumped

  • Kotlin to 1.8.20
  • KSP version to 1.8.20-1.0.10

1.0.1 - 2023-03-20

Added

From now on there are two versions of the ktorfit-lib.

“de.jensklingenberg.ktorfit:ktorfit-lib” will stay like before and add the platform client dependencies for the clients.

“de.jensklingenberg.ktorfit:ktorfit-lib-light” this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as “ktorfit-lib”

Changed

Deprecated

Removed

Fixed

[Bug]: Post request body serialization doesn’t work #202

Security

Bumped


1.0.0 - 2023-03-02

This project is now following semver

Added

  • internal optimizations
  • throw compile error when generated class can not be found

Fixed

  • Timeout throws exception outside of scope of SuspendResponseConverter #127
  • Fix broken/outdated docs link (#140) by @T-Spoon

Bumped

  • based on Ktor 2.2.4

1.0.0-beta18 (12-02-2023)

NEW:

  • You can now disable the check if the baseUrl ends with a /
Ktorfit.Builder().baseUrl(testBaseUrl, checkUrl = false).build()
+
  • Ktorfit is now using converters factories to apply the converters, similar to Retrofit see more here https://foso.github.io/Ktorfit/converters/converters/
  • TypeData now has a field “typeInfo” can be used to convert the Ktor HttpResponse body to the wanted type
  • CallConverterFactory for replacement of CallResponseConverter
  • FlowConverterFactory for replacement of FlowResponseConverter

  • Added support for targets: macosArm64, tvosArm64, tvosX64, tvosSimulatorArm64, watchosSimulatorArm64 #315

Changed

  • Upgrade dependencies: Kotlin 1.8.21

Deprecated

  • ResponseConverter, use Converter.ResponseConverter instead
  • SuspendResponseConverter, use Converter.SuspendResponseConverter instead
  • RequestConverter, use Converter.RequestParameterConverter instead
  • See also: https://foso.github.io/Ktorfit/converters/migration/

Removed

Fixed

Security

1.3.0 - 2023-05-14

Added

Changed

  • Optimized generated code, the generated code that is used for a request will now directly set the Ktor code instead of delegating it to a Ktorfit class. This will make the code easier to understand.

  • KSP version 1.0.11 is now needed

Deprecated

Removed

Fixed

[Bug]: IllegalArgumentException with Custom Http Annotation #274

Security

Bumped

KSP version to 1.0.11

1.2.0 - 2023-05-05

Added

Changed

Deprecated

Removed

Fixed

Security

Bumped

Now based on Ktor 2.3.0

1.1.0 - 2023-04-15

Added

From now on there are two versions of the ktorfit-lib.

“de.jensklingenberg.ktorfit:ktorfit-lib” will stay like before and add the platform client dependencies for the clients.

“de.jensklingenberg.ktorfit:ktorfit-lib-light” this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as “ktorfit-lib”

Changed

  • Kotlin version 1.8.20 is now needed
  • KSP version 1.8.20-1.0.10 is now needed

Deprecated

Removed

Fixed

Security

Bumped

  • Kotlin to 1.8.20
  • KSP version to 1.8.20-1.0.10

1.0.1 - 2023-03-20

Added

From now on there are two versions of the ktorfit-lib.

“de.jensklingenberg.ktorfit:ktorfit-lib” will stay like before and add the platform client dependencies for the clients.

“de.jensklingenberg.ktorfit:ktorfit-lib-light” this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as “ktorfit-lib”

Changed

Deprecated

Removed

Fixed

[Bug]: Post request body serialization doesn’t work #202

Security

Bumped


1.0.0 - 2023-03-02

This project is now following semver

Added

  • internal optimizations
  • throw compile error when generated class can not be found

Fixed

  • Timeout throws exception outside of scope of SuspendResponseConverter #127
  • Fix broken/outdated docs link (#140) by @T-Spoon

Bumped

  • based on Ktor 2.2.4

1.0.0-beta18 (12-02-2023)

NEW:

  • You can now disable the check if the baseUrl ends with a /
Ktorfit.Builder().baseUrl(testBaseUrl, checkUrl = false).build()
 

🐛 Bugs fixed

  • Fixed Ktorfit breaking incremental compilation #110

⬆️ Deps updates

  • based on Ktor 2.2.3

1.0.0-beta17 (21-01-2023)

💥 Breaking changes:

  • Ktorfit now needs an additional gradle plugin. This will solve several issues with multi-module projects.

Add this plugin:

plugins {
   id "de.jensklingenberg.ktorfit" version "1.0.0"
 }
@@ -32,4 +32,4 @@
 "Authorization: token ghp_abcdefgh",
 "Content-Type: application/json"
 )
-

1.0.0-beta09

  • 15 fix encoding of query parameters

1.0.0-beta08

  • fix issue with Koin Annotations

1.0.0-beta07

  • fix issue with FormUrlEncoded
  • based on Ktor 2.0.2

1.0.0-beta06

  • fix issue with KSP 1.0.5 #19

1.0.0-beta05

  • fixed: Custom Http Method with @Body is now possible #6
  • based on Ktor 2.0.1
  • cleanup example project @mattrob33

1.0.0-beta04

initial release


Last update: August 2, 2023
\ No newline at end of file +

1.0.0-beta09

  • 15 fix encoding of query parameters

1.0.0-beta08

  • fix issue with Koin Annotations

1.0.0-beta07

  • fix issue with FormUrlEncoded
  • based on Ktor 2.0.2

1.0.0-beta06

  • fix issue with KSP 1.0.5 #19

1.0.0-beta05

  • fixed: Custom Http Method with @Body is now possible #6
  • based on Ktor 2.0.1
  • cleanup example project @mattrob33

1.0.0-beta04

initial release


Last update: August 4, 2023
\ No newline at end of file diff --git a/search/search_index.json b/search/search_index.json index a40e56b02..17c8f36af 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Overview","text":"Ktorfit"},{"location":"#introduction","title":"Introduction","text":"

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

"},{"location":"#installation","title":"Installation","text":"

Please see Installation

"},{"location":"#quick-start","title":"Quick start","text":"

Please see Quick start

"},{"location":"#requests","title":"Requests","text":"

See Requests

"},{"location":"#converters","title":"Converters","text":"

See documentation Here

"},{"location":"#changelog","title":"Changelog","text":"

See changelog

"},{"location":"#acknowledgments","title":"Acknowledgments","text":"

Some parts of this project are reusing ideas that are originally coming from Retrofit from Square. Thank you for Retrofit!

Thanks to JetBrains for Ktor and Kotlin!

"},{"location":"#contributions","title":"Contributions","text":"

When you find unexpected behaviour please write an issue

"},{"location":"CHANGELOG/","title":"Changelog","text":"

All important changes of this project must be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

"},{"location":"CHANGELOG/#unreleased","title":"[Unreleased]","text":""},{"location":"CHANGELOG/#added","title":"Added","text":""},{"location":"CHANGELOG/#changed","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed","title":"Removed","text":""},{"location":"CHANGELOG/#fixed","title":"Fixed","text":""},{"location":"CHANGELOG/#security","title":"Security","text":""},{"location":"CHANGELOG/#144-2023-07-26","title":"1.4.4 - 2023-07-26","text":""},{"location":"CHANGELOG/#added_1","title":"Added","text":""},{"location":"CHANGELOG/#changed_1","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_1","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_1","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_1","title":"Fixed","text":""},{"location":"CHANGELOG/#security_1","title":"Security","text":""},{"location":"CHANGELOG/#143-2023-07-13","title":"1.4.3 - 2023-07-13","text":""},{"location":"CHANGELOG/#added_2","title":"Added","text":""},{"location":"CHANGELOG/#changed_2","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_2","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_2","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_2","title":"Fixed","text":""},{"location":"CHANGELOG/#372-crash-with-xiaomi-on-create-ktorfitbuilder-by-princeparadoxes","title":"372 Crash with Xiaomi on create Ktorfit.Builder by @princeparadoxes","text":""},{"location":"CHANGELOG/#security_2","title":"Security","text":""},{"location":"CHANGELOG/#142-2023-06-25","title":"1.4.2 - 2023-06-25","text":""},{"location":"CHANGELOG/#added_3","title":"Added","text":""},{"location":"CHANGELOG/#changed_3","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_3","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_3","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_3","title":"Fixed","text":""},{"location":"CHANGELOG/#323-code-generation-issue-for-multipart-formurlencoded-by-ph1ll1pp","title":"323 Code generation issue for @Multipart / @FormUrlEncoded by @Ph1ll1pp","text":""},{"location":"CHANGELOG/#security_3","title":"Security","text":""},{"location":"CHANGELOG/#141-2023-06-03","title":"1.4.1 - 2023-06-03","text":""},{"location":"CHANGELOG/#added_4","title":"Added","text":""},{"location":"CHANGELOG/#changed_4","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_4","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_4","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_4","title":"Fixed","text":""},{"location":"CHANGELOG/#236-parsing-error-for-listarray","title":"236 Parsing error for list/array","text":""},{"location":"CHANGELOG/#security_4","title":"Security","text":""},{"location":"CHANGELOG/#140-2023-05-27","title":"1.4.0 - 2023-05-27","text":""},{"location":"CHANGELOG/#added_5","title":"Added","text":"

e.g.

interface ExampleApi{\nsuspend fun getUser(): Response<User>\n}\n\nval user = userKtorfit.create<ExampleApi>().getUser()\n\nif(user.isSuccessful){\nuser.body()\n}else{\nuser.errorBody()\n}\n
"},{"location":"CHANGELOG/#85-added-a-response-class-that-can-be-used-as-a-wrapper-around-the-api-response-the-converter-for-it-is-automatically-applied-thx-to-vovahost-datl4g","title":"85 Added a Response class that can be used as a wrapper around the API Response, the converter for it is automatically applied. thx to @vovahost, @DATL4G","text":""},{"location":"CHANGELOG/#changed_5","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_5","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_5","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_5","title":"Fixed","text":""},{"location":"CHANGELOG/#security_5","title":"Security","text":""},{"location":"CHANGELOG/#130-2023-05-14","title":"1.3.0 - 2023-05-14","text":""},{"location":"CHANGELOG/#added_6","title":"Added","text":""},{"location":"CHANGELOG/#changed_6","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_6","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_6","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_6","title":"Fixed","text":"

[Bug]: IllegalArgumentException with Custom Http Annotation #274

"},{"location":"CHANGELOG/#security_6","title":"Security","text":""},{"location":"CHANGELOG/#bumped","title":"Bumped","text":"

KSP version to 1.0.11

"},{"location":"CHANGELOG/#120-2023-05-05","title":"1.2.0 - 2023-05-05","text":""},{"location":"CHANGELOG/#added_7","title":"Added","text":""},{"location":"CHANGELOG/#changed_7","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_7","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_7","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_7","title":"Fixed","text":""},{"location":"CHANGELOG/#security_7","title":"Security","text":""},{"location":"CHANGELOG/#bumped_1","title":"Bumped","text":"

Now based on Ktor 2.3.0

"},{"location":"CHANGELOG/#110-2023-04-15","title":"1.1.0 - 2023-04-15","text":""},{"location":"CHANGELOG/#added_8","title":"Added","text":"

From now on there are two versions of the ktorfit-lib.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib\u201d will stay like before and add the platform client dependencies for the clients.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib-light\u201d this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as \u201cktorfit-lib\u201d

"},{"location":"CHANGELOG/#changed_8","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_8","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_8","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_8","title":"Fixed","text":""},{"location":"CHANGELOG/#security_8","title":"Security","text":""},{"location":"CHANGELOG/#bumped_2","title":"Bumped","text":""},{"location":"CHANGELOG/#101-2023-03-20","title":"1.0.1 - 2023-03-20","text":""},{"location":"CHANGELOG/#added_9","title":"Added","text":"

From now on there are two versions of the ktorfit-lib.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib\u201d will stay like before and add the platform client dependencies for the clients.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib-light\u201d this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as \u201cktorfit-lib\u201d

"},{"location":"CHANGELOG/#changed_9","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_9","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_9","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_9","title":"Fixed","text":"

[Bug]: Post request body serialization doesn\u2019t work #202

"},{"location":"CHANGELOG/#security_9","title":"Security","text":""},{"location":"CHANGELOG/#bumped_3","title":"Bumped","text":""},{"location":"CHANGELOG/#100-2023-03-02","title":"1.0.0 - 2023-03-02","text":"

This project is now following semver

"},{"location":"CHANGELOG/#added_10","title":"Added","text":""},{"location":"CHANGELOG/#fixed_10","title":"Fixed","text":""},{"location":"CHANGELOG/#bumped_4","title":"Bumped","text":""},{"location":"CHANGELOG/#100-beta18-12-02-2023","title":"1.0.0-beta18 (12-02-2023)","text":"

NEW:

Ktorfit.Builder().baseUrl(testBaseUrl, checkUrl = false).build()\n

\ud83d\udc1b Bugs fixed

\u2b06\ufe0f Deps updates

"},{"location":"CHANGELOG/#100-beta17-21-01-2023","title":"1.0.0-beta17 (21-01-2023)","text":"

\ud83d\udca5 Breaking changes:

Add this plugin:

plugins {\nid \"de.jensklingenberg.ktorfit\" version \"1.0.0\"\n}\n

NEW:

\ud83d\udc1b Bugs fixed

\u2b06\ufe0f Deps updates

"},{"location":"CHANGELOG/#100-beta16-13-11-2022","title":"1.0.0-beta16 (13-11-2022)","text":"

NEW: - Field parameters can now be nullable, null values will be ignored in requests - Add option to turn of error checking

ksp { arg(\u201cKtorfit_Errors\u201d, \u201c1\u201d) }

You can set it in your build.gradle.kts file,

0: Turn off all Ktorfit related error checking

1: Check for errors

2: Turn errors into warnings

\u2b06\ufe0f Deps updates

\ud83d\udc1b Bugs fixed

"},{"location":"CHANGELOG/#whats-changed","title":"What\u2019s Changed","text":"

Full Changelog: https://github.com/Foso/Ktorfit/compare/v1.0.0-beta15...v1.0.0-beta16

"},{"location":"CHANGELOG/#100-beta15-05-10-2022","title":"1.0.0-beta15 (05-10-2022)","text":"

\u2b06\ufe0f Deps updates

\ud83d\udc1b Bugs fixed

\ud83d\udca5 Breaking changes

"},{"location":"CHANGELOG/#100-beta14-24-09-2022","title":"1.0.0-beta14 (24-09-2022)","text":"

NEW: - Query parameters can now be nullable, null values will be ignored in requests - Function return types can now be nullable

FIX: - Url annotation not resolved correctly #65

BREAKING CHANGES: - Changed naming of Converters:

"},{"location":"CHANGELOG/#100-beta13-10-09-2022","title":"1.0.0-beta13 (10-09-2022)","text":"

Fixed: - Url annotation not resolved correctly #52

"},{"location":"CHANGELOG/#100-beta12-31-08-2022","title":"1.0.0-beta12 (31-08-2022)","text":""},{"location":"CHANGELOG/#breaking-changes","title":"Breaking Changes:","text":"

wrapResponse from SuspendResponseConverter got renamed to wrapSuspendResponse. This add the possibility to have ResponseConverter and SuspendResponseConverter implemented in the same class.

"},{"location":"CHANGELOG/#changes","title":"Changes:","text":"

val ktorfit = ktorfit {\nbaseUrl(\"http://example.com/\")\n}.create<GithubService>()\n
or this

val ktorfit = ktorfit {\nbaseUrl(\"http://example.com/\")\n}.createGithubService()\n

By default, IntelliJ/Android Studio can\u2019t find the generated code, you need to add the KSP generated folder to the sourcesets like this: (See more here: https://kotlinlang.org/docs/ksp-quickstart.html#make-ide-aware-of-generated-code)

kotlin.srcDir(\"build/generated/ksp/jvm/jvmMain/\")\n
"},{"location":"CHANGELOG/#100-beta11-21-08-2022","title":"1.0.0-beta11 (21-08-2022)","text":""},{"location":"CHANGELOG/#100-beta10-18-08-2022","title":"1.0.0-beta10 (18-08-2022)","text":"

to this:

Ktorfit.Builder()\n.baseUrl(\"https://example.com/\")\n.httpClient(HttpClient {})\n.build()\n
"},{"location":"CHANGELOG/#breaking-changes_1","title":"Breaking Changes:","text":"

@Headers now requires a vararg of String instead of an Array e.g. you need to change from:

@Headers(\n[\"Authorization: token ghp_abcdefgh\",\n\"Content-Type: application/json\"]\n)\n

to this:

@Headers(\n\"Authorization: token ghp_abcdefgh\",\n\"Content-Type: application/json\"\n)\n

"},{"location":"CHANGELOG/#100-beta09","title":"1.0.0-beta09","text":""},{"location":"CHANGELOG/#15-fix-encoding-of-query-parameters","title":"15 fix encoding of query parameters","text":""},{"location":"CHANGELOG/#100-beta08","title":"1.0.0-beta08","text":""},{"location":"CHANGELOG/#100-beta07","title":"1.0.0-beta07","text":""},{"location":"CHANGELOG/#100-beta06","title":"1.0.0-beta06","text":""},{"location":"CHANGELOG/#100-beta05","title":"1.0.0-beta05","text":""},{"location":"CHANGELOG/#100-beta04","title":"1.0.0-beta04","text":"

initial release

"},{"location":"License/","title":"License","text":"
                             Apache License\n                       Version 2.0, January 2004\n                    http://www.apache.org/licenses/\n

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

  1. Definitions.

    \u201cLicense\u201d shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

    \u201cLicensor\u201d shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

    \u201cLegal Entity\u201d shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, \u201ccontrol\u201d means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

    \u201cYou\u201d (or \u201cYour\u201d) shall mean an individual or Legal Entity exercising permissions granted by this License.

    \u201cSource\u201d form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

    \u201cObject\u201d form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

    \u201cWork\u201d shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

    \u201cDerivative Works\u201d shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

    \u201cContribution\u201d shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, \u201csubmitted\u201d means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as \u201cNot a Contribution.\u201d

    \u201cContributor\u201d shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

  2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

  3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

  4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

    (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and

    (b) You must cause any modified files to carry prominent notices stating that You changed the files; and

    \u00a9 You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and

    (d) If the Work includes a \u201cNOTICE\u201d text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

    You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.

  5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

  6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

  7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an \u201cAS IS\u201d BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

  8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

  9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

  To apply the Apache License to your work, attach the following\n  boilerplate notice, with the fields enclosed by brackets \"[]\"\n  replaced with your own identifying information. (Don't include\n  the brackets!)  The text should be enclosed in the appropriate\n  comment syntax for the file format. We also recommend that a\n  file or class name and description of purpose be included on the\n  same \"printed page\" as the copyright notice for easier\n  identification within third-party archives.\n

Copyright 2022 Jens Klingenberg

Licensed under the Apache License, Version 2.0 (the \u201cLicense\u201d); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0\n

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \u201cAS IS\u201d BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

"},{"location":"architecture/","title":"How Ktorfit works under the hood","text":"

Ktorfit consists of three main components KSP-Plugin, Compiler plugin and the Ktorfit lib

"},{"location":"architecture/#ksp-plugin","title":"KSP-Plugin","text":"

This will generate the code for the implementation of the interfaces

"},{"location":"architecture/#compiler-plugin","title":"Compiler plugin","text":"

This transforms the create() function from the Ktorfit lib

"},{"location":"architecture/#ktorfit-lib","title":"Ktorfit lib","text":"

A wrapper around Ktor to simplify code generation

"},{"location":"architecture/#example","title":"Example","text":"

package com.example\n\nimport com.example.model.People\nimport de.jensklingenberg.ktorfit.http.GET\n\ninterface ExampleApi  {\n@GET(\"/test\")\nsuspend fun exampleGet(): People\n}\n
Let`s say we have a interface like this.

At compile time Ktorfit/KSP checks for all functions that are annotated with Ktorfit annotations like @GET.

Then it looks at the parent interfaces of that functions and generates, the source code of a Kotlin class that implements the interface. The classes are named like the interfaces but with an underscore at the beginning and \u201cImpl\u201d at the end, and they have the same package as the interfaces. In this case a class named _ExampleApiImpl will be generated. The class will also implement KtorfitService. The setClient() function will be used to add the http client at runtime.

@OptIn(InternalKtorfitApi::class)\npublic class _ExampleApiImpl : ExampleApi, KtorfitService {\npublic override lateinit var ktorfitClient: Client\n\npublic override suspend fun exampleGet(): String {\nval _ext: HttpRequestBuilder.() -> Unit = {\nmethod = HttpMethod.parse(\"GET\")\nurl(ktorfitClient.baseUrl + \"/test\")\n}\nval _requestData = RequestData(returnTypeData = TypeData(\"kotlin.String\"),\nrequestTypeInfo = typeInfo<String>(),\nreturnTypeInfo = typeInfo<String>(),\nktorfitRequestBuilder = _ext)\n\nreturn ktorfitClient.suspendRequest<String, String>(_requestData)!!\n}\n}\n\npublic fun Ktorfit.createExampleApi(): ExampleApi = this.create(_ExampleApiImpl())\n

The next part is the compiler plugin which is added by the gradle plugin. It looks for the every usage of the create function from the Ktorfit-lib and adds an object of the wanted implementation class as an argument. Because of the naming convention of the generated classes we can deduce the name of the class from the name of type parameter.

val api = jvmKtorfit.create<ExampleApi>()\n

will be transformed to:

val api = jvmKtorfit.create<ExampleApi>(_ExampleApiImpl())\n

When the create() function is used, the object is cast to a KtorfitService and the client will be added. Then it is cast to requested type < T >

fun <T> create(ktorfitService: KtorfitService = DefaultKtorfitService()): T {\nif (ktorfitService is DefaultKtorfitService) {\nthrow IllegalArgumentException(\"You need to enable the Ktorfit Gradle Plugin\")\n}\nktorfitService.setClient(KtorfitClient(this))\nreturn ktorfitService as T\n}\n
"},{"location":"configuration/","title":"Compile errors","text":"

By default, Ktorfit will throw compile error when it finds conditions under which it can\u2019t ensure that it will work correct. You can set an KSP argument to change this:

ksp {\narg(\"Ktorfit_Errors\", \"1\")\n}\n

You can set it in your build.gradle.kts file,

0: Turn off all Ktorfit related error checking

1: Check for errors

2: Turn errors into warnings

"},{"location":"configuration/#add-your-own-ktor-client","title":"Add your own Ktor client","text":"

You can set your Ktor client instance to the Ktorfit builder:

val myClient = HttpClient()\nval ktorfit = Ktorfit.Builder().httpClient(myClient).build()\n
"},{"location":"development/","title":"Development","text":""},{"location":"installation/","title":"Installation","text":""},{"location":"installation/#setup","title":"Setup","text":"

(You can also look how it\u2019s done in the examples)

"},{"location":"installation/#gradle-plugins","title":"Gradle Plugins","text":"

You need to add KSP and the Ktorfit Gradle plugin

plugins {\nid(\"com.google.devtools.ksp\") version \"CURRENT_KSP_VERSION\"\nid(\"de.jensklingenberg.ktorfit\") version \"1.0.0\"\n}\n\nconfigure<de.jensklingenberg.ktorfit.gradle.KtorfitGradleConfiguration> {\nversion = \"1.4.4\"\n}\n

Next you have to add the Ktorfit KSP Plugin to the common target and every compilation target, where you want to use Ktorfit.

val ktorfitVersion = \"1.4.4\"\n\ndependencies {\nadd(\"kspCommonMainMetadata\", \"de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion\")\nadd(\"ksp[NAMEOFPLATFORM]\",\"de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion\")\n...\n}\n

[NAMEOFPLATFORM] is the name of the compilation target. When you want to use it for the Android module it\u2019s kspAndroid, for Js it\u2019s kspJs, etc. Look here for more information https://kotlinlang.org/docs/ksp-multiplatform.html

"},{"location":"installation/#ktorfit-lib","title":"Ktorfit-lib","text":"

Add the Ktorfit-lib to your common module.

val ktorfitVersion = \"1.4.4\"\n\nsourceSets {\nval commonMain by getting{\ndependencies{\nimplementation(\"de.jensklingenberg.ktorfit:ktorfit-lib:$ktorfitVersion\")\n}\n}\n

"},{"location":"installation/#ktor","title":"Ktor","text":"

Ktorfit is based on Ktor clients 2.3.2. You don\u2019t need to add an extra dependency for the default clients. When you want to use Ktor plugins for things like serialization, you need to add the dependencies, and they need to be compatible with 2.3.2

You can also use \u201cde.jensklingenberg.ktorfit:ktorfit-lib-light\u201d this will only add the Ktor client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as \u201cktorfit-lib\u201d

"},{"location":"quick-start/","title":"Quick start","text":"

First do the Installation

Let\u2019s say you want to make a GET Request to https://swapi.dev/api/people/1/

Create a new Kotlin interface:

interface ExampleApi {\n@GET(\"people/1/\")\nsuspend fun getPerson(): String\n}\n

Now we add a function that will be used to make our request. The @GET annotation will tell Ktorfit that this a GET request. The value of @GET is the relative URL path that will be appended to the base url which we set later.

An interface used for Ktorfit needs to have a HTTP method annotation on every function. Because Ktor relies on Coroutines by default your functions need to have the suspend modifier. Alternatively you can use #Flow or Call

Info

The return type String will return the response text. When you want directly parse the response into a class you need to add a JSON,XML, etc. converter to Ktor

val ktorfit = Ktorfit.Builder().baseUrl(\"https://swapi.dev/api/\").build()\nval exampleApi = ktorfit.create<ExampleApi>()\n

Next we use the Ktorfit builder to create a Ktorfit instance, and set the base url . We can then use the create() function to receive an implementation of the wanted type.

val response = exampleApi.getPerson()\nprintln(response)\n

Now we can use exampleApi to make the request.

"},{"location":"requests/","title":"Requests","text":""},{"location":"requests/#http-request","title":"HTTP Request","text":"

Ktorfit supports the following the HTTP method annotations:

Or you can set your custom method to @HTTP

@GET(\"posts\")\nfun getPosts(): List<Post>\n

The value of the HTTP annotation will be appended to the baseUrl that you set in the Ktorfit builder. If the value contains a url that starts with http or https, this url will be used for the request instead of the baseUrl.

@GET(\"https://example.com/posts\")\nfun getPosts(): List<Post>\n

The value can only be empty when you also use @Url

"},{"location":"requests/#url","title":"Url","text":"

Can be used to set a URL dynamically as a function parameter.

@GET(\"\")\nsuspend fun getPosts(@Url url: String): List<Post>\n

"},{"location":"requests/#query","title":"Query","text":"
@GET(\"comments\")\nsuspend fun getCommentsById(\n@Query(\"postId\") postId: String,\n@QueryName queryName: String,\n@QueryMap headerMap : Map<String,String>\n): List<Comment>\n

You can use @Query, @QueryName or @QueryMap to set queries to your request.

Example:

@GET(\"comments\")\nsuspend fun getCommentsById(@Query(\"postId\") postId: String): List<Comment>\n

A request with getCommentsById(3) will result in the relative URL \u201ccomments?postId=3\u201d

"},{"location":"requests/#path","title":"Path","text":"

When you want to dynamically replace a part of the URL, you can use the @Path annotation.

interface ExampleApi {\n@GET(\"people/{peopleId}/\")\nsuspend fun getPerson(@Path(\"peopleId\") id: String): String\n}\n
Just write a part of your URL path in curly braces. Then you need to annotate a parameter with @Path. The value of @Path needs to match with one of the curly braces part in your URL path.

Example:

On a request with getPerson(1) , {peopleId} will be replaced with the argument 1 and the relative URL will become \u201cpeople/1/\u201d

"},{"location":"requests/#headers","title":"Headers","text":"
@Headers(\"Accept: application/json\")\n@GET(\"comments\")\nsuspend fun requestWithHeaders(\n@Header(\"Content-Type\") name: String,\n@HeaderMap headerMap : Map<String,String>\n): List<Comment>\n

You can use @Headers, @Header or @HeaderMap to configure headers to your request.

"},{"location":"requests/#body","title":"Body","text":"
interface ExampleService {\n@POST(\"upload\")\nsuspend fun upload(@Body data: String)\n}\n

@Body can be used as parameter to send data in a request body. It can only be used with Http Methods that have a request body

"},{"location":"requests/#formdata","title":"FormData","text":"
@POST(\"signup\")\n@FormUrlEncoded\nsuspend fun signup(\n@Field(\"username\") username: String, @Field(\"email\") email: String,\n@Field(\"password\") password: String, @Field(\"confirmation\") confirmation: String\n): String\n

To send FormData you can use @Field or @FieldMap. Your function needs to be annotated with @FormUrlEncoded.

"},{"location":"requests/#multipart","title":"Multipart","text":"

To send Multipart data you have two options:

"},{"location":"requests/#1-body","title":"1) @Body","text":"
interface ExampleService {\n@POST(\"upload\")\nsuspend fun upload(@Body map: MultiPartFormDataContent)\n}\n

To upload MultiPartFormData you need to have a parameter of the type MultiPartFormDataContent that is annotated with @Body. The method needs to be annotated with @POST or @PUT

val multipart = MultiPartFormDataContent(formData {\nappend(\"description\", \"Ktor logo\")\nappend(\"image\", File(\"ktor_logo.png\").readBytes(), Headers.build {\nappend(HttpHeaders.ContentType, \"image/png\")\nappend(HttpHeaders.ContentDisposition, \"filename=ktor_logo.png\")\n})\n})\n\nexampleApi.upload(multipart)\n

Then you can use Ktor\u2019s formData Builder to create the MultiPartFormDataContent

"},{"location":"requests/#2-multipart","title":"2) @MultiPart","text":"
@Multipart\n@POST(\"upload\")\nsuspend fun uploadFile(@Part(\"description\") description: String, @Part(\"\") file: List<PartData>): String\n

You can annotate a function with @Multipart. Then you can annotate parameters with @Part

val multipart = formData {\nappend(\"image\", File(\"ktor_logo.png\").readBytes(), Headers.build {\nappend(HttpHeaders.ContentType, \"image/png\")\nappend(HttpHeaders.ContentDisposition, \"filename=ktor_logo.png\")\n})\n}\n\nexampleApi.upload(\"Ktor logo\",multipart)\n

All your parameters annotated with @Part wil be combined and send as MultiPartFormDataContent

"},{"location":"requests/#json","title":"JSON","text":"

Ktorfit doesn\u2019t parse JSON. You have to install the Json Feature to the Ktor Client that you add to Ktorfit.

See here Add your own Ktor client and here https://ktor.io/docs/serialization-client.html

val ktorClient = HttpClient() {\ninstall(ContentNegotiation) {\njson(Json { isLenient = true; ignoreUnknownKeys = true })\n}\n}\n
"},{"location":"requests/#streaming","title":"Streaming","text":"
@Streaming\n@GET(\"docs/response.html#streaming\")\nsuspend fun getPostsStreaming(): HttpStatement\n

To receive streaming data you need to annotate a function with @Streaming and the return type has to be HttpStatement.

exampleApi.getPostsStreaming().execute { response ->\n//Do something with response\n}\n

For more information check Ktor docs

"},{"location":"requests/#requestbuilder","title":"RequestBuilder","text":"
@GET(\"comments\")\nsuspend fun getCommentsById(\n@Query(\"postId\") name: String,\n@ReqBuilder ext: HttpRequestBuilder.() -> Unit\n): List<Comment>\n

You need to set extra configuration on your request? Add a parameter with \u201c@ReqBuilder ext: HttpRequestBuilder.() -> Unit\u201d to your function.

val result = secondApi.getCommentsById(\"3\") {\nonDownload { bytesSentTotal, contentLength ->\nprintln(bytesSentTotal)\n}\n}\n

Then you can use the extension function to set additional configuration. The RequestBuilder will be applied last after everything that is set by Ktorfit

"},{"location":"responseconverter/","title":"Responseconverter","text":"

ResponseConverter is deprecated, use Converter.ResponseConverter instead

Let`s say you have a function that requests a list of comments

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): List<Comment>\n

But now you want to directly wrap your comment list in your data holder class e.g. \u201cMyOwnResponse\u201d

sealed class MyOwnResponse<T> {\ndata class Success<T>(val data: T) : MyOwnResponse<T>()\nclass Error(val ex:Throwable) : MyOwnResponse<Nothing>()\n\ncompanion object {\nfun <T> success(data: T) = Success(data)\nfun error(ex: Throwable) = Error(ex)\n}\n}\n

To enable that, you have to implement a ResponseConverter. This class will be used to wrap the Ktor response inside your wrapper class.

class MyOwnResponseConverter : ResponseConverter {\n\noverride suspend fun <RequestType> wrapResponse(\ntypeData: TypeData,\nrequestFunction: suspend () -> Pair<TypeInfo, HttpResponse>,\nktorfit: Ktorfit\n): Any {\nreturn try {\nval (info, response) = requestFunction()\nMyOwnResponse.success<Any>(response.body(info))\n} catch (ex: Throwable) {\nMyOwnResponse.error(ex)\n}\n}\n\noverride fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {\nreturn typeData.qualifiedName == \"com.example.model.MyOwnResponse\"\n}\n}\n

You can then add the ResponseConverter on your Ktorfit object.

ktorfit.responseConverter(MyOwnResponseConverter())\n

Now add MyOwnResponse to your function

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): MyOwnResponse<List<Comment>>\n

"},{"location":"suspendresponseconverter/","title":"Suspendresponseconverter","text":"

SuspendResponseConverter is deprecated, use Converter.SuspendResponseConverter instead

Because Ktor relies on Coroutines by default your functions need to have the suspend modifier.

To change this, you need to use a SuspendResponseConverter, you add your own or use Flow or Call

You can add RequestConverter on your Ktorfit object.

ktorfit.responseConverter(FlowResponseConverter())\n
"},{"location":"suspendresponseconverter/#flow","title":"Flow","text":"

Ktorfit has support for Kotlin Flow. You need add the FlowResponseConverter() to your Ktorfit instance.

ktorfit.responseConverter(FlowResponseConverter())\n
@GET(\"comments\")\nfun getCommentsById(@Query(\"postId\") postId: String): Flow<List<Comment>>\n

Then you can drop the suspend modifier and wrap your return type with Flow<>

"},{"location":"suspendresponseconverter/#call","title":"Call","text":"

ktorfit.responseConverter(CallResponseConverter())\n
@GET(\"people/{id}/\")\nfun getPersonById(@Path(\"id\") peopleId: Int): Call<People>\n

exampleApi.getPersonById(3).onExecute(object : Callback<People>{\noverride fun onResponse(call: People, response: HttpResponse) {\n//Do something with Response\n}\n\noverride fun onError(exception: Exception) {\n//Do something with exception\n}\n})\n

You can use Call to receive the response in a Callback."},{"location":"suspendresponseconverter/#your-own","title":"Your own","text":"

You can also add your own Converter. You just need to implement RequestConverter. Inside the converter you need to handle the conversion from suspend to your async code.

class MyOwnResponseConverter : SuspendResponseConverter {\n...\n
"},{"location":"converters/converters/","title":"Converters","text":"

Converters are used to convert the HTTPResponse or parameters.

They are added inside of a Converter.Factory which will then be added to the Ktorfit builder with the converterfactories() function.

"},{"location":"converters/converters/#converter-types","title":"Converter Types","text":""},{"location":"converters/converters/#existing-converter-factories","title":"Existing converter factories","text":""},{"location":"converters/example1/","title":"Example1","text":"

Let\u2019s say you want to get an user from an API and the response you get looks like below:

API response
{\n\"success\": true,\n\"user\":\n{\n\"id\": 1,\n\"name\": \"Jens Klingenberg\"\n}\n}\n

But you are only interested in the \u201cuser\u201d object, and you want to look your interface function something like this:

Example function
@GET(\"/user\")\nsuspend fun getUser(): User\n

First you need the Kotlin classes to which your JSON data is mapped to:

This example assumes that you are Kotlin Serialization

@kotlinx.serialization.Serializable\ndata class Envelope(val success: Boolean, val user: User)\n\n@kotlinx.serialization.Serializable\ndata class User(val id: Int, val name: String)\n

Now you need a converter that can convert the HTTPResponse and return a user object. Create a class that extends Converter.Factory

class UserFactory : Converter.Factory {\n\n}\n

Because in this case User is the return type of a suspend function, you need to create a SuspendResponseConverter. Override suspendResponseConverter()

class UserFactory : Converter.Factory {\noverride fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\n\n}\n}\n

Inside suspendResponseConverter you can decide if you want to return a converter. In our case we a converter for the type User. We can check that case with the typeData that we get as a parameter.

override fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == User::class) {\n...\n}\nreturn null\n}\n

Next we create the SuspendResponseConverter:

if (typeData.typeInfo.type == User::class) {\nreturn object : Converter.SuspendResponseConverter<HttpResponse, Any> {\noverride suspend fun convert(response: HttpResponse): Any {\n...\n}\n}\n}\n
Inside of convert we get the HttpResponse and we want to return a User object.

Now we could do the following:

When we know that this converter will always be used for a API that wraps the User inside an Envelope class, we can directly transform the body to an envelope object and just return the user object.

override suspend fun convert(response: HttpResponse): Any {\nval envelope = response.body<Envelope>()\nreturn envelope.user\n}\n

or we can create a TypeData of Envelope and use nextSuspendResponseConverter() to look up the next converter that can convert the response

 override suspend fun convert(response: HttpResponse): Any {\nval typeData = TypeData.createTypeData(\"com.example.model.Envelope\", typeInfo<Envelope>())\nval envelope = ktorfit.nextSuspendResponseConverter(null, typeData)?.convert(response) as? Envelope\nreturn envelope.user\n}\n

Finally, add your converter factory to the Ktorfit Builder

Ktorfit.Builder().converterFactories(UserFactory()).baseUrl(\"foo\").build()\n
"},{"location":"converters/migration/","title":"Migration","text":" SuspendResponseConverter
 override suspend fun <RequestType> wrapSuspendResponse(\ntypeData: TypeData,\nrequestFunction: suspend () -> Pair<TypeInfo, HttpResponse>,\nktorfit: Ktorfit\n): Any {\nreturn object : Call<RequestType> {\noverride fun onExecute(callBack: Callback<RequestType>) {\n\nktorfit.httpClient.launch {\nval deferredResponse = async { requestFunction() }\n\nval (data, response) = deferredResponse.await()\n\ntry {\nval res = response.call.body(data)\ncallBack.onResponse(res as RequestType, response)\n} catch (ex: Exception) {\ncallBack.onError(ex)\n} } } } }\n\noverride fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {\nreturn typeData.qualifiedName == \"de.jensklingenberg.ktorfit.Call\"\n}\n
Equivalent with converter factory:
public class CallConverterFactory : Converter.Factory {\n\noverride fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == Call::class) {\nreturn object: Converter.SuspendResponseConverter<HttpResponse, Call<Any?>> {\noverride suspend fun convert(response: HttpResponse): Call<Any?> {\n\nreturn object : Call<Any?> {\noverride fun onExecute(callBack: Callback<Any?>) {\nktorfit.httpClient.launch {\ntry {\nval data = response.call.body(typeData.typeArgs.first().typeInfo)\ncallBack.onResponse(data!!, response)\n} catch (ex: Exception) {\ncallBack.onError(ex)\n} } } } } } }\nreturn null\n}\n}\n
ResponseConverter
override fun <RequestType> wrapResponse(\ntypeData: TypeData,\nrequestFunction: suspend () -> Pair<TypeInfo, HttpResponse?>,\nktorfit: Ktorfit\n): Any {\nreturn object : Call<RequestType> {\noverride fun onExecute(callBack: Callback<RequestType>) {\n\nktorfit.httpClient.launch {\nval deferredResponse = async { requestFunction() }\n\ntry {\nval (info, response) = deferredResponse.await()\nval data = response!!.body(info) as RequestType\ncallBack.onResponse(data, response)\n} catch (ex: Exception) {\ncallBack.onError(ex)\n}\n\n}\n}\n\n}\n}\n\noverride fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {\nreturn typeData.qualifiedName == \"de.jensklingenberg.ktorfit.Call\"\n}\n
Equivalent with converter factory:
public class CallConverterFactory : Converter.Factory {\noverride fun responseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.ResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == Call::class) {\nreturn object : Converter.ResponseConverter<HttpResponse, Call<Any?>> {\n\noverride fun convert(getResponse: suspend () -> HttpResponse): Call<Any?> {\nreturn object : Call<Any?> {\noverride fun onExecute(callBack: Callback<Any?>) {\nktorfit.httpClient.launch {\ntry {\nval response = getResponse()\n\nval data = response.call.body(typeData.typeArgs.first().typeInfo)\n\ncallBack.onResponse(data, response)\n} catch (ex: Exception) {\nprintln(ex)\ncallBack.onError(ex)\n} } } } } } }\nreturn null\n}\n}\n
"},{"location":"converters/requestparameterconverter/","title":"RequestParameterConverter","text":"
@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsById(@RequestType(Int::class) @Path(\"postId\") postId: String): List<Comment>\n

You can set RequestType at a parameter with a type to which the parameter should be converted.

Then you need to implement a Converter factory with a RequestParameterConverter.

class StringToIntRequestConverterFactory : Converter.Factory {\noverride fun requestParameterConverter(\nparameterType: KClass<*>,\nrequestType: KClass<*>\n): Converter.RequestParameterConverter? {\nreturn object : Converter.RequestParameterConverter {\noverride fun convert(data: Any): Any {\n//convert the data\n}\n}\n}\n}\n
ktorfit.converterFactories(StringToIntRequestConverterFactory())\n
"},{"location":"converters/responseconverter/","title":"ResponseConverter","text":"

You only need ResponseConverters for cases where you can\u2019t use a suspend function in your interface. For every other case you want SuspendResponseConverter

Because Ktor relies on Coroutines by default your functions need to have the suspend modifier.

Let\u2019s say you have API endpoint to get a list of comments and you want to get them as Flow.

Ktorfit already has a converter for Flow, but it\u2019s used as an example

@GET(\"/user\")\nfun getUser(): Flow<List<Commment>>\n

Now you need a converter that can convert the HTTPResponse and return a Flow. Create a class that extends Converter.Factory

class FlowConverterFactory : Converter.Factory {\n}\n

Next you need to overwrite responseConverter()

override fun responseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.ResponseConverter<HttpResponse, *>? {\n

Inside responseConverter you can decide if you want to return a converter. In our case we want a converter for the type Flow. We can check that case with the typeData that we get as a parameter.

override fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == Flow::class) {\n...\n}\nreturn null\n}\n

Next we create the ResponseConverter:

if (typeData.typeInfo.type == User::class) {\nval requestType = typeData.typeArgs.first()\n\nreturn object : Converter.ResponseConverter<HttpResponse, Flow<Any>> {\noverride fun convert(getResponse: suspend () -> HttpResponse): Flow<Any> {\nreturn flow {\ntry {\nval response = getResponse()\nif (requestType.typeInfo.type == HttpResponse::class) {\nemit(response)\n} else {\nval data = ktorfit.nextSuspendResponseConverter(this@FlowConverterFactory, requestType)\n?.convert(response)\nemit(data)\n}\n} catch (exception: Exception) {\nthrow exception\n}\n}\n}\n}\n}\n

Inside of convert we get the HttpResponse from getResponse(). We use nextSuspendResponseConverter to find the next converter that can convert the response. Then we put the converted response in the Flow and return it.

Finally, add your converter factory to the Ktorfit Builder

Ktorfit.Builder().converterFactories(FlowConverterFactory()).baseUrl(\"foo\").build()\n
"},{"location":"converters/responseconverter/#flow","title":"Flow","text":"

Ktorfit has support for Kotlin Flow. You need add the FlowConverterFactory() to your Ktorfit instance.

ktorfit.converterFactories(FlowConverterFactory())\n
@GET(\"comments\")\nfun getCommentsById(@Query(\"postId\") postId: String): Flow<List<Comment>>\n

Then you can drop the suspend modifier and wrap your return type with Flow<>

"},{"location":"converters/responseconverter/#call","title":"Call","text":"
ktorfit.converterFactories(CallConverterFactory())\n
@GET(\"people/{id}/\")\nfun getPersonById(@Path(\"id\") peopleId: Int): Call<People>\n
exampleApi.getPersonById(3).onExecute(object : Callback<People> {\noverride fun onResponse(call: People, response: HttpResponse) {\n//Do something with Response\n}\n\noverride fun onError(exception: Exception) {\n//Do something with exception\n}\n})\n

You can use Call to receive the response in a Callback."},{"location":"converters/suspendresponseconverter/","title":"SuspendResponseConverter","text":"

Let`s say you have a function that requests a list of comments

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): List<Comment>\n

But now you want to directly wrap your comment list in your data holder class e.g. \u201cMyOwnResponse\u201d

sealed class MyOwnResponse<T> {\ndata class Success<T>(val data: T) : MyOwnResponse<T>()\nclass Error(val ex:Throwable) : MyOwnResponse<Nothing>()\n\ncompanion object {\nfun <T> success(data: T) = Success(data)\nfun error(ex: Throwable) = Error(ex)\n}\n}\n

To enable that, you have to implement a SuspendResponseConverter. This class will be used to wrap the Ktor response inside your wrapper class.

class MyOwnResponseConverterFactory : Converter.Factory{\n\noverride fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif(typeData.typeInfo.type == MyOwnResponse::class) {\n\nreturn object : Converter.SuspendResponseConverter<HttpResponse, Any> {\noverride suspend fun convert(response: HttpResponse): Any {\nreturn try {\nMyOwnResponse.success(response.body(typeData.typeArgs.first().typeInfo))\n} catch (ex: Throwable) {\nMyOwnResponse.error(ex)\n}\n}\n}\n}\nreturn null\n}\n}\n

You can then add the ResponseConverter to your Ktorfit object.

ktorfit.converterFactories(MyOwnResponseConverterFactory())\n

Now add MyOwnResponse to your function

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): MyOwnResponse<List<Comment>>\n

"},{"location":"fundamentals/scope/","title":"Scope of Ktorfit","text":"

The goal of Ktorfit is to provide a similar developer experience like Retrofit for Kotlin Multiplatform projects. It`s not a 100% drop-in replacement for Retrofit. It uses Ktor clients because they are available on nearly every compile target of KMP. Every feature should be implemented so that it works on all platforms that Ktor supports. Before a new functionality is added to Ktorfit, it should be checked if there is already a Ktor plugin for it which solves the same problem.

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Overview","text":"Ktorfit"},{"location":"#introduction","title":"Introduction","text":"

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

"},{"location":"#installation","title":"Installation","text":"

Please see Installation

"},{"location":"#quick-start","title":"Quick start","text":"

Please see Quick start

"},{"location":"#requests","title":"Requests","text":"

See Requests

"},{"location":"#converters","title":"Converters","text":"

See documentation Here

"},{"location":"#changelog","title":"Changelog","text":"

See changelog

"},{"location":"#acknowledgments","title":"Acknowledgments","text":"

Some parts of this project are reusing ideas that are originally coming from Retrofit from Square. Thank you for Retrofit!

Thanks to JetBrains for Ktor and Kotlin!

"},{"location":"#contributions","title":"Contributions","text":"

When you find unexpected behaviour please write an issue

"},{"location":"CHANGELOG/","title":"Changelog","text":"

All important changes of this project must be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

"},{"location":"CHANGELOG/#unreleased","title":"[Unreleased]","text":""},{"location":"CHANGELOG/#added","title":"Added","text":""},{"location":"CHANGELOG/#changed","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed","title":"Removed","text":""},{"location":"CHANGELOG/#fixed","title":"Fixed","text":""},{"location":"CHANGELOG/#security","title":"Security","text":"

1.5.0 - 2023-08-04

"},{"location":"CHANGELOG/#added_1","title":"Added","text":""},{"location":"CHANGELOG/#changed_1","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_1","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_1","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_1","title":"Fixed","text":""},{"location":"CHANGELOG/#security_1","title":"Security","text":""},{"location":"CHANGELOG/#144-2023-07-26","title":"1.4.4 - 2023-07-26","text":""},{"location":"CHANGELOG/#added_2","title":"Added","text":""},{"location":"CHANGELOG/#changed_2","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_2","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_2","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_2","title":"Fixed","text":""},{"location":"CHANGELOG/#security_2","title":"Security","text":""},{"location":"CHANGELOG/#143-2023-07-13","title":"1.4.3 - 2023-07-13","text":""},{"location":"CHANGELOG/#added_3","title":"Added","text":""},{"location":"CHANGELOG/#changed_3","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_3","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_3","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_3","title":"Fixed","text":""},{"location":"CHANGELOG/#372-crash-with-xiaomi-on-create-ktorfitbuilder-by-princeparadoxes","title":"372 Crash with Xiaomi on create Ktorfit.Builder by @princeparadoxes","text":""},{"location":"CHANGELOG/#security_3","title":"Security","text":""},{"location":"CHANGELOG/#142-2023-06-25","title":"1.4.2 - 2023-06-25","text":""},{"location":"CHANGELOG/#added_4","title":"Added","text":""},{"location":"CHANGELOG/#changed_4","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_4","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_4","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_4","title":"Fixed","text":""},{"location":"CHANGELOG/#323-code-generation-issue-for-multipart-formurlencoded-by-ph1ll1pp","title":"323 Code generation issue for @Multipart / @FormUrlEncoded by @Ph1ll1pp","text":""},{"location":"CHANGELOG/#security_4","title":"Security","text":""},{"location":"CHANGELOG/#141-2023-06-03","title":"1.4.1 - 2023-06-03","text":""},{"location":"CHANGELOG/#added_5","title":"Added","text":""},{"location":"CHANGELOG/#changed_5","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_5","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_5","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_5","title":"Fixed","text":""},{"location":"CHANGELOG/#236-parsing-error-for-listarray","title":"236 Parsing error for list/array","text":""},{"location":"CHANGELOG/#security_5","title":"Security","text":""},{"location":"CHANGELOG/#140-2023-05-27","title":"1.4.0 - 2023-05-27","text":""},{"location":"CHANGELOG/#added_6","title":"Added","text":"

e.g.

interface ExampleApi{\nsuspend fun getUser(): Response<User>\n}\n\nval user = userKtorfit.create<ExampleApi>().getUser()\n\nif(user.isSuccessful){\nuser.body()\n}else{\nuser.errorBody()\n}\n
"},{"location":"CHANGELOG/#85-added-a-response-class-that-can-be-used-as-a-wrapper-around-the-api-response-the-converter-for-it-is-automatically-applied-thx-to-vovahost-datl4g","title":"85 Added a Response class that can be used as a wrapper around the API Response, the converter for it is automatically applied. thx to @vovahost, @DATL4G","text":""},{"location":"CHANGELOG/#changed_6","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_6","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_6","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_6","title":"Fixed","text":""},{"location":"CHANGELOG/#security_6","title":"Security","text":""},{"location":"CHANGELOG/#130-2023-05-14","title":"1.3.0 - 2023-05-14","text":""},{"location":"CHANGELOG/#added_7","title":"Added","text":""},{"location":"CHANGELOG/#changed_7","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_7","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_7","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_7","title":"Fixed","text":"

[Bug]: IllegalArgumentException with Custom Http Annotation #274

"},{"location":"CHANGELOG/#security_7","title":"Security","text":""},{"location":"CHANGELOG/#bumped","title":"Bumped","text":"

KSP version to 1.0.11

"},{"location":"CHANGELOG/#120-2023-05-05","title":"1.2.0 - 2023-05-05","text":""},{"location":"CHANGELOG/#added_8","title":"Added","text":""},{"location":"CHANGELOG/#changed_8","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_8","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_8","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_8","title":"Fixed","text":""},{"location":"CHANGELOG/#security_8","title":"Security","text":""},{"location":"CHANGELOG/#bumped_1","title":"Bumped","text":"

Now based on Ktor 2.3.0

"},{"location":"CHANGELOG/#110-2023-04-15","title":"1.1.0 - 2023-04-15","text":""},{"location":"CHANGELOG/#added_9","title":"Added","text":"

From now on there are two versions of the ktorfit-lib.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib\u201d will stay like before and add the platform client dependencies for the clients.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib-light\u201d this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as \u201cktorfit-lib\u201d

"},{"location":"CHANGELOG/#changed_9","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_9","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_9","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_9","title":"Fixed","text":""},{"location":"CHANGELOG/#security_9","title":"Security","text":""},{"location":"CHANGELOG/#bumped_2","title":"Bumped","text":""},{"location":"CHANGELOG/#101-2023-03-20","title":"1.0.1 - 2023-03-20","text":""},{"location":"CHANGELOG/#added_10","title":"Added","text":"

From now on there are two versions of the ktorfit-lib.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib\u201d will stay like before and add the platform client dependencies for the clients.

\u201cde.jensklingenberg.ktorfit:ktorfit-lib-light\u201d this will only add the client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as \u201cktorfit-lib\u201d

"},{"location":"CHANGELOG/#changed_10","title":"Changed","text":""},{"location":"CHANGELOG/#deprecated_10","title":"Deprecated","text":""},{"location":"CHANGELOG/#removed_10","title":"Removed","text":""},{"location":"CHANGELOG/#fixed_10","title":"Fixed","text":"

[Bug]: Post request body serialization doesn\u2019t work #202

"},{"location":"CHANGELOG/#security_10","title":"Security","text":""},{"location":"CHANGELOG/#bumped_3","title":"Bumped","text":""},{"location":"CHANGELOG/#100-2023-03-02","title":"1.0.0 - 2023-03-02","text":"

This project is now following semver

"},{"location":"CHANGELOG/#added_11","title":"Added","text":""},{"location":"CHANGELOG/#fixed_11","title":"Fixed","text":""},{"location":"CHANGELOG/#bumped_4","title":"Bumped","text":""},{"location":"CHANGELOG/#100-beta18-12-02-2023","title":"1.0.0-beta18 (12-02-2023)","text":"

NEW:

Ktorfit.Builder().baseUrl(testBaseUrl, checkUrl = false).build()\n

\ud83d\udc1b Bugs fixed

\u2b06\ufe0f Deps updates

"},{"location":"CHANGELOG/#100-beta17-21-01-2023","title":"1.0.0-beta17 (21-01-2023)","text":"

\ud83d\udca5 Breaking changes:

Add this plugin:

plugins {\nid \"de.jensklingenberg.ktorfit\" version \"1.0.0\"\n}\n

NEW:

\ud83d\udc1b Bugs fixed

\u2b06\ufe0f Deps updates

"},{"location":"CHANGELOG/#100-beta16-13-11-2022","title":"1.0.0-beta16 (13-11-2022)","text":"

NEW: - Field parameters can now be nullable, null values will be ignored in requests - Add option to turn of error checking

ksp { arg(\u201cKtorfit_Errors\u201d, \u201c1\u201d) }

You can set it in your build.gradle.kts file,

0: Turn off all Ktorfit related error checking

1: Check for errors

2: Turn errors into warnings

\u2b06\ufe0f Deps updates

\ud83d\udc1b Bugs fixed

"},{"location":"CHANGELOG/#whats-changed","title":"What\u2019s Changed","text":"

Full Changelog: https://github.com/Foso/Ktorfit/compare/v1.0.0-beta15...v1.0.0-beta16

"},{"location":"CHANGELOG/#100-beta15-05-10-2022","title":"1.0.0-beta15 (05-10-2022)","text":"

\u2b06\ufe0f Deps updates

\ud83d\udc1b Bugs fixed

\ud83d\udca5 Breaking changes

"},{"location":"CHANGELOG/#100-beta14-24-09-2022","title":"1.0.0-beta14 (24-09-2022)","text":"

NEW: - Query parameters can now be nullable, null values will be ignored in requests - Function return types can now be nullable

FIX: - Url annotation not resolved correctly #65

BREAKING CHANGES: - Changed naming of Converters:

"},{"location":"CHANGELOG/#100-beta13-10-09-2022","title":"1.0.0-beta13 (10-09-2022)","text":"

Fixed: - Url annotation not resolved correctly #52

"},{"location":"CHANGELOG/#100-beta12-31-08-2022","title":"1.0.0-beta12 (31-08-2022)","text":""},{"location":"CHANGELOG/#breaking-changes","title":"Breaking Changes:","text":"

wrapResponse from SuspendResponseConverter got renamed to wrapSuspendResponse. This add the possibility to have ResponseConverter and SuspendResponseConverter implemented in the same class.

"},{"location":"CHANGELOG/#changes","title":"Changes:","text":"

val ktorfit = ktorfit {\nbaseUrl(\"http://example.com/\")\n}.create<GithubService>()\n
or this

val ktorfit = ktorfit {\nbaseUrl(\"http://example.com/\")\n}.createGithubService()\n

By default, IntelliJ/Android Studio can\u2019t find the generated code, you need to add the KSP generated folder to the sourcesets like this: (See more here: https://kotlinlang.org/docs/ksp-quickstart.html#make-ide-aware-of-generated-code)

kotlin.srcDir(\"build/generated/ksp/jvm/jvmMain/\")\n
"},{"location":"CHANGELOG/#100-beta11-21-08-2022","title":"1.0.0-beta11 (21-08-2022)","text":""},{"location":"CHANGELOG/#100-beta10-18-08-2022","title":"1.0.0-beta10 (18-08-2022)","text":"

to this:

Ktorfit.Builder()\n.baseUrl(\"https://example.com/\")\n.httpClient(HttpClient {})\n.build()\n
"},{"location":"CHANGELOG/#breaking-changes_1","title":"Breaking Changes:","text":"

@Headers now requires a vararg of String instead of an Array e.g. you need to change from:

@Headers(\n[\"Authorization: token ghp_abcdefgh\",\n\"Content-Type: application/json\"]\n)\n

to this:

@Headers(\n\"Authorization: token ghp_abcdefgh\",\n\"Content-Type: application/json\"\n)\n

"},{"location":"CHANGELOG/#100-beta09","title":"1.0.0-beta09","text":""},{"location":"CHANGELOG/#15-fix-encoding-of-query-parameters","title":"15 fix encoding of query parameters","text":""},{"location":"CHANGELOG/#100-beta08","title":"1.0.0-beta08","text":""},{"location":"CHANGELOG/#100-beta07","title":"1.0.0-beta07","text":""},{"location":"CHANGELOG/#100-beta06","title":"1.0.0-beta06","text":""},{"location":"CHANGELOG/#100-beta05","title":"1.0.0-beta05","text":""},{"location":"CHANGELOG/#100-beta04","title":"1.0.0-beta04","text":"

initial release

"},{"location":"License/","title":"License","text":"
                             Apache License\n                       Version 2.0, January 2004\n                    http://www.apache.org/licenses/\n

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

  1. Definitions.

    \u201cLicense\u201d shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

    \u201cLicensor\u201d shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

    \u201cLegal Entity\u201d shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, \u201ccontrol\u201d means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

    \u201cYou\u201d (or \u201cYour\u201d) shall mean an individual or Legal Entity exercising permissions granted by this License.

    \u201cSource\u201d form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

    \u201cObject\u201d form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

    \u201cWork\u201d shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

    \u201cDerivative Works\u201d shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

    \u201cContribution\u201d shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, \u201csubmitted\u201d means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as \u201cNot a Contribution.\u201d

    \u201cContributor\u201d shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

  2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

  3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

  4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

    (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and

    (b) You must cause any modified files to carry prominent notices stating that You changed the files; and

    \u00a9 You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and

    (d) If the Work includes a \u201cNOTICE\u201d text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

    You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.

  5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

  6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

  7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an \u201cAS IS\u201d BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

  8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

  9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

  To apply the Apache License to your work, attach the following\n  boilerplate notice, with the fields enclosed by brackets \"[]\"\n  replaced with your own identifying information. (Don't include\n  the brackets!)  The text should be enclosed in the appropriate\n  comment syntax for the file format. We also recommend that a\n  file or class name and description of purpose be included on the\n  same \"printed page\" as the copyright notice for easier\n  identification within third-party archives.\n

Copyright 2022 Jens Klingenberg

Licensed under the Apache License, Version 2.0 (the \u201cLicense\u201d); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0\n

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \u201cAS IS\u201d BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

"},{"location":"architecture/","title":"How Ktorfit works under the hood","text":"

Ktorfit consists of three main components KSP-Plugin, Compiler plugin and the Ktorfit lib

"},{"location":"architecture/#ksp-plugin","title":"KSP-Plugin","text":"

This will generate the code for the implementation of the interfaces

"},{"location":"architecture/#compiler-plugin","title":"Compiler plugin","text":"

This transforms the create() function from the Ktorfit lib

"},{"location":"architecture/#ktorfit-lib","title":"Ktorfit lib","text":"

A wrapper around Ktor to simplify code generation

"},{"location":"architecture/#example","title":"Example","text":"

package com.example\n\nimport com.example.model.People\nimport de.jensklingenberg.ktorfit.http.GET\n\ninterface ExampleApi  {\n@GET(\"/test\")\nsuspend fun exampleGet(): People\n}\n
Let`s say we have a interface like this.

At compile time Ktorfit/KSP checks for all functions that are annotated with Ktorfit annotations like @GET.

Then it looks at the parent interfaces of that functions and generates, the source code of a Kotlin class that implements the interface. The classes are named like the interfaces but with an underscore at the beginning and \u201cImpl\u201d at the end, and they have the same package as the interfaces. In this case a class named _ExampleApiImpl will be generated. The class will also implement KtorfitService. The setClient() function will be used to add the http client at runtime.

@OptIn(InternalKtorfitApi::class)\npublic class _ExampleApiImpl : ExampleApi, KtorfitService {\npublic override lateinit var ktorfitClient: Client\n\npublic override suspend fun exampleGet(): String {\nval _ext: HttpRequestBuilder.() -> Unit = {\nmethod = HttpMethod.parse(\"GET\")\nurl(ktorfitClient.baseUrl + \"/test\")\n}\nval _requestData = RequestData(returnTypeData = TypeData(\"kotlin.String\"),\nrequestTypeInfo = typeInfo<String>(),\nreturnTypeInfo = typeInfo<String>(),\nktorfitRequestBuilder = _ext)\n\nreturn ktorfitClient.suspendRequest<String, String>(_requestData)!!\n}\n}\n\npublic fun Ktorfit.createExampleApi(): ExampleApi = this.create(_ExampleApiImpl())\n

The next part is the compiler plugin which is added by the gradle plugin. It looks for the every usage of the create function from the Ktorfit-lib and adds an object of the wanted implementation class as an argument. Because of the naming convention of the generated classes we can deduce the name of the class from the name of type parameter.

val api = jvmKtorfit.create<ExampleApi>()\n

will be transformed to:

val api = jvmKtorfit.create<ExampleApi>(_ExampleApiImpl())\n

When the create() function is used, the object is cast to a KtorfitService and the client will be added. Then it is cast to requested type < T >

fun <T> create(ktorfitService: KtorfitService = DefaultKtorfitService()): T {\nif (ktorfitService is DefaultKtorfitService) {\nthrow IllegalArgumentException(\"You need to enable the Ktorfit Gradle Plugin\")\n}\nktorfitService.setClient(KtorfitClient(this))\nreturn ktorfitService as T\n}\n
"},{"location":"configuration/","title":"Compile errors","text":"

By default, Ktorfit will throw compile error when it finds conditions under which it can\u2019t ensure that it will work correct. You can set an KSP argument to change this:

ksp {\narg(\"Ktorfit_Errors\", \"1\")\n}\n

You can set it in your build.gradle.kts file,

0: Turn off all Ktorfit related error checking

1: Check for errors

2: Turn errors into warnings

"},{"location":"configuration/#add-your-own-ktor-client","title":"Add your own Ktor client","text":"

You can set your Ktor client instance to the Ktorfit builder:

val myClient = HttpClient()\nval ktorfit = Ktorfit.Builder().httpClient(myClient).build()\n
"},{"location":"development/","title":"Development","text":""},{"location":"installation/","title":"Installation","text":""},{"location":"installation/#setup","title":"Setup","text":"

(You can also look how it\u2019s done in the examples)

"},{"location":"installation/#gradle-plugins","title":"Gradle Plugins","text":"

You need to add KSP and the Ktorfit Gradle plugin

plugins {\nid(\"com.google.devtools.ksp\") version \"CURRENT_KSP_VERSION\"\nid(\"de.jensklingenberg.ktorfit\") version \"1.0.0\"\n}\n\nconfigure<de.jensklingenberg.ktorfit.gradle.KtorfitGradleConfiguration> {\nversion = \"1.4.4\"\n}\n

Next you have to add the Ktorfit KSP Plugin to the common target and every compilation target, where you want to use Ktorfit.

val ktorfitVersion = \"1.4.4\"\n\ndependencies {\nadd(\"kspCommonMainMetadata\", \"de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion\")\nadd(\"ksp[NAMEOFPLATFORM]\",\"de.jensklingenberg.ktorfit:ktorfit-ksp:$ktorfitVersion\")\n...\n}\n

[NAMEOFPLATFORM] is the name of the compilation target. When you want to use it for the Android module it\u2019s kspAndroid, for Js it\u2019s kspJs, etc. Look here for more information https://kotlinlang.org/docs/ksp-multiplatform.html

"},{"location":"installation/#ktorfit-lib","title":"Ktorfit-lib","text":"

Add the Ktorfit-lib to your common module.

val ktorfitVersion = \"1.4.4\"\n\nsourceSets {\nval commonMain by getting{\ndependencies{\nimplementation(\"de.jensklingenberg.ktorfit:ktorfit-lib:$ktorfitVersion\")\n}\n}\n

"},{"location":"installation/#ktor","title":"Ktor","text":"

Ktorfit is based on Ktor clients 2.3.2. You don\u2019t need to add an extra dependency for the default clients. When you want to use Ktor plugins for things like serialization, you need to add the dependencies, and they need to be compatible with 2.3.2

You can also use \u201cde.jensklingenberg.ktorfit:ktorfit-lib-light\u201d this will only add the Ktor client core dependency and not the platform dependencies for the clients. This will give you more control over the used clients, but you have to add them yourself. https://ktor.io/docs/http-client-engines.html Everything else is the same as \u201cktorfit-lib\u201d

"},{"location":"quick-start/","title":"Quick start","text":"

First do the Installation

Let\u2019s say you want to make a GET Request to https://swapi.dev/api/people/1/

Create a new Kotlin interface:

interface ExampleApi {\n@GET(\"people/1/\")\nsuspend fun getPerson(): String\n}\n

Now we add a function that will be used to make our request. The @GET annotation will tell Ktorfit that this a GET request. The value of @GET is the relative URL path that will be appended to the base url which we set later.

An interface used for Ktorfit needs to have a HTTP method annotation on every function. Because Ktor relies on Coroutines by default your functions need to have the suspend modifier. Alternatively you can use #Flow or Call

Info

The return type String will return the response text. When you want directly parse the response into a class you need to add a JSON,XML, etc. converter to Ktor

val ktorfit = Ktorfit.Builder().baseUrl(\"https://swapi.dev/api/\").build()\nval exampleApi = ktorfit.create<ExampleApi>()\n

Next we use the Ktorfit builder to create a Ktorfit instance, and set the base url . We can then use the create() function to receive an implementation of the wanted type.

val response = exampleApi.getPerson()\nprintln(response)\n

Now we can use exampleApi to make the request.

"},{"location":"requests/","title":"Requests","text":""},{"location":"requests/#http-request","title":"HTTP Request","text":"

Ktorfit supports the following the HTTP method annotations:

Or you can set your custom method to @HTTP

@GET(\"posts\")\nfun getPosts(): List<Post>\n

The value of the HTTP annotation will be appended to the baseUrl that you set in the Ktorfit builder. If the value contains a url that starts with http or https, this url will be used for the request instead of the baseUrl.

@GET(\"https://example.com/posts\")\nfun getPosts(): List<Post>\n

The value can only be empty when you also use @Url

"},{"location":"requests/#url","title":"Url","text":"

Can be used to set a URL dynamically as a function parameter.

@GET(\"\")\nsuspend fun getPosts(@Url url: String): List<Post>\n

"},{"location":"requests/#query","title":"Query","text":"
@GET(\"comments\")\nsuspend fun getCommentsById(\n@Query(\"postId\") postId: String,\n@QueryName queryName: String,\n@QueryMap headerMap : Map<String,String>\n): List<Comment>\n

You can use @Query, @QueryName or @QueryMap to set queries to your request.

Example:

@GET(\"comments\")\nsuspend fun getCommentsById(@Query(\"postId\") postId: String): List<Comment>\n

A request with getCommentsById(3) will result in the relative URL \u201ccomments?postId=3\u201d

"},{"location":"requests/#path","title":"Path","text":"

When you want to dynamically replace a part of the URL, you can use the @Path annotation.

interface ExampleApi {\n@GET(\"people/{peopleId}/\")\nsuspend fun getPerson(@Path(\"peopleId\") id: String): String\n}\n
Just write a part of your URL path in curly braces. Then you need to annotate a parameter with @Path. The value of @Path needs to match with one of the curly braces part in your URL path.

Example:

On a request with getPerson(1) , {peopleId} will be replaced with the argument 1 and the relative URL will become \u201cpeople/1/\u201d

"},{"location":"requests/#headers","title":"Headers","text":"
@Headers(\"Accept: application/json\")\n@GET(\"comments\")\nsuspend fun requestWithHeaders(\n@Header(\"Content-Type\") name: String,\n@HeaderMap headerMap : Map<String,String>\n): List<Comment>\n

You can use @Headers, @Header or @HeaderMap to configure headers to your request.

"},{"location":"requests/#body","title":"Body","text":"
interface ExampleService {\n@POST(\"upload\")\nsuspend fun upload(@Body data: String)\n}\n

@Body can be used as parameter to send data in a request body. It can only be used with Http Methods that have a request body

"},{"location":"requests/#formdata","title":"FormData","text":"
@POST(\"signup\")\n@FormUrlEncoded\nsuspend fun signup(\n@Field(\"username\") username: String, @Field(\"email\") email: String,\n@Field(\"password\") password: String, @Field(\"confirmation\") confirmation: String\n): String\n

To send FormData you can use @Field or @FieldMap. Your function needs to be annotated with @FormUrlEncoded.

"},{"location":"requests/#multipart","title":"Multipart","text":"

To send Multipart data you have two options:

"},{"location":"requests/#1-body","title":"1) @Body","text":"
interface ExampleService {\n@POST(\"upload\")\nsuspend fun upload(@Body map: MultiPartFormDataContent)\n}\n

To upload MultiPartFormData you need to have a parameter of the type MultiPartFormDataContent that is annotated with @Body. The method needs to be annotated with @POST or @PUT

val multipart = MultiPartFormDataContent(formData {\nappend(\"description\", \"Ktor logo\")\nappend(\"image\", File(\"ktor_logo.png\").readBytes(), Headers.build {\nappend(HttpHeaders.ContentType, \"image/png\")\nappend(HttpHeaders.ContentDisposition, \"filename=ktor_logo.png\")\n})\n})\n\nexampleApi.upload(multipart)\n

Then you can use Ktor\u2019s formData Builder to create the MultiPartFormDataContent

"},{"location":"requests/#2-multipart","title":"2) @MultiPart","text":"
@Multipart\n@POST(\"upload\")\nsuspend fun uploadFile(@Part(\"description\") description: String, @Part(\"\") file: List<PartData>): String\n

You can annotate a function with @Multipart. Then you can annotate parameters with @Part

val multipart = formData {\nappend(\"image\", File(\"ktor_logo.png\").readBytes(), Headers.build {\nappend(HttpHeaders.ContentType, \"image/png\")\nappend(HttpHeaders.ContentDisposition, \"filename=ktor_logo.png\")\n})\n}\n\nexampleApi.upload(\"Ktor logo\",multipart)\n

All your parameters annotated with @Part wil be combined and send as MultiPartFormDataContent

"},{"location":"requests/#json","title":"JSON","text":"

Ktorfit doesn\u2019t parse JSON. You have to install the Json Feature to the Ktor Client that you add to Ktorfit.

See here Add your own Ktor client and here https://ktor.io/docs/serialization-client.html

val ktorClient = HttpClient() {\ninstall(ContentNegotiation) {\njson(Json { isLenient = true; ignoreUnknownKeys = true })\n}\n}\n
"},{"location":"requests/#streaming","title":"Streaming","text":"
@Streaming\n@GET(\"docs/response.html#streaming\")\nsuspend fun getPostsStreaming(): HttpStatement\n

To receive streaming data you need to annotate a function with @Streaming and the return type has to be HttpStatement.

exampleApi.getPostsStreaming().execute { response ->\n//Do something with response\n}\n

For more information check Ktor docs

"},{"location":"requests/#requestbuilder","title":"RequestBuilder","text":"
@GET(\"comments\")\nsuspend fun getCommentsById(\n@Query(\"postId\") name: String,\n@ReqBuilder ext: HttpRequestBuilder.() -> Unit\n): List<Comment>\n

You need to set extra configuration on your request? Add a parameter with \u201c@ReqBuilder ext: HttpRequestBuilder.() -> Unit\u201d to your function.

val result = secondApi.getCommentsById(\"3\") {\nonDownload { bytesSentTotal, contentLength ->\nprintln(bytesSentTotal)\n}\n}\n

Then you can use the extension function to set additional configuration. The RequestBuilder will be applied last after everything that is set by Ktorfit

"},{"location":"responseconverter/","title":"Responseconverter","text":"

ResponseConverter is deprecated, use Converter.ResponseConverter instead

Let`s say you have a function that requests a list of comments

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): List<Comment>\n

But now you want to directly wrap your comment list in your data holder class e.g. \u201cMyOwnResponse\u201d

sealed class MyOwnResponse<T> {\ndata class Success<T>(val data: T) : MyOwnResponse<T>()\nclass Error(val ex:Throwable) : MyOwnResponse<Nothing>()\n\ncompanion object {\nfun <T> success(data: T) = Success(data)\nfun error(ex: Throwable) = Error(ex)\n}\n}\n

To enable that, you have to implement a ResponseConverter. This class will be used to wrap the Ktor response inside your wrapper class.

class MyOwnResponseConverter : ResponseConverter {\n\noverride suspend fun <RequestType> wrapResponse(\ntypeData: TypeData,\nrequestFunction: suspend () -> Pair<TypeInfo, HttpResponse>,\nktorfit: Ktorfit\n): Any {\nreturn try {\nval (info, response) = requestFunction()\nMyOwnResponse.success<Any>(response.body(info))\n} catch (ex: Throwable) {\nMyOwnResponse.error(ex)\n}\n}\n\noverride fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {\nreturn typeData.qualifiedName == \"com.example.model.MyOwnResponse\"\n}\n}\n

You can then add the ResponseConverter on your Ktorfit object.

ktorfit.responseConverter(MyOwnResponseConverter())\n

Now add MyOwnResponse to your function

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): MyOwnResponse<List<Comment>>\n

"},{"location":"suspendresponseconverter/","title":"Suspendresponseconverter","text":"

SuspendResponseConverter is deprecated, use Converter.SuspendResponseConverter instead

Because Ktor relies on Coroutines by default your functions need to have the suspend modifier.

To change this, you need to use a SuspendResponseConverter, you add your own or use Flow or Call

You can add RequestConverter on your Ktorfit object.

ktorfit.responseConverter(FlowResponseConverter())\n
"},{"location":"suspendresponseconverter/#flow","title":"Flow","text":"

Ktorfit has support for Kotlin Flow. You need add the FlowResponseConverter() to your Ktorfit instance.

ktorfit.responseConverter(FlowResponseConverter())\n
@GET(\"comments\")\nfun getCommentsById(@Query(\"postId\") postId: String): Flow<List<Comment>>\n

Then you can drop the suspend modifier and wrap your return type with Flow<>

"},{"location":"suspendresponseconverter/#call","title":"Call","text":"

ktorfit.responseConverter(CallResponseConverter())\n
@GET(\"people/{id}/\")\nfun getPersonById(@Path(\"id\") peopleId: Int): Call<People>\n

exampleApi.getPersonById(3).onExecute(object : Callback<People>{\noverride fun onResponse(call: People, response: HttpResponse) {\n//Do something with Response\n}\n\noverride fun onError(exception: Exception) {\n//Do something with exception\n}\n})\n

You can use Call to receive the response in a Callback."},{"location":"suspendresponseconverter/#your-own","title":"Your own","text":"

You can also add your own Converter. You just need to implement RequestConverter. Inside the converter you need to handle the conversion from suspend to your async code.

class MyOwnResponseConverter : SuspendResponseConverter {\n...\n
"},{"location":"converters/converters/","title":"Converters","text":"

Converters are used to convert the HTTPResponse or parameters.

They are added inside of a Converter.Factory which will then be added to the Ktorfit builder with the converterfactories() function.

"},{"location":"converters/converters/#converter-types","title":"Converter Types","text":""},{"location":"converters/converters/#existing-converter-factories","title":"Existing converter factories","text":""},{"location":"converters/example1/","title":"Example1","text":"

Let\u2019s say you want to get an user from an API and the response you get looks like below:

API response
{\n\"success\": true,\n\"user\":\n{\n\"id\": 1,\n\"name\": \"Jens Klingenberg\"\n}\n}\n

But you are only interested in the \u201cuser\u201d object, and you want to look your interface function something like this:

Example function
@GET(\"/user\")\nsuspend fun getUser(): User\n

First you need the Kotlin classes to which your JSON data is mapped to:

This example assumes that you are Kotlin Serialization

@kotlinx.serialization.Serializable\ndata class Envelope(val success: Boolean, val user: User)\n\n@kotlinx.serialization.Serializable\ndata class User(val id: Int, val name: String)\n

Now you need a converter that can convert the HTTPResponse and return a user object. Create a class that extends Converter.Factory

class UserFactory : Converter.Factory {\n\n}\n

Because in this case User is the return type of a suspend function, you need to create a SuspendResponseConverter. Override suspendResponseConverter()

class UserFactory : Converter.Factory {\noverride fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\n\n}\n}\n

Inside suspendResponseConverter you can decide if you want to return a converter. In our case we a converter for the type User. We can check that case with the typeData that we get as a parameter.

override fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == User::class) {\n...\n}\nreturn null\n}\n

Next we create the SuspendResponseConverter:

if (typeData.typeInfo.type == User::class) {\nreturn object : Converter.SuspendResponseConverter<HttpResponse, Any> {\noverride suspend fun convert(response: HttpResponse): Any {\n...\n}\n}\n}\n
Inside of convert we get the HttpResponse and we want to return a User object.

Now we could do the following:

When we know that this converter will always be used for a API that wraps the User inside an Envelope class, we can directly transform the body to an envelope object and just return the user object.

override suspend fun convert(response: HttpResponse): Any {\nval envelope = response.body<Envelope>()\nreturn envelope.user\n}\n

or we can create a TypeData of Envelope and use nextSuspendResponseConverter() to look up the next converter that can convert the response

 override suspend fun convert(response: HttpResponse): Any {\nval typeData = TypeData.createTypeData(\"com.example.model.Envelope\", typeInfo<Envelope>())\nval envelope = ktorfit.nextSuspendResponseConverter(null, typeData)?.convert(response) as? Envelope\nreturn envelope.user\n}\n

Finally, add your converter factory to the Ktorfit Builder

Ktorfit.Builder().converterFactories(UserFactory()).baseUrl(\"foo\").build()\n
"},{"location":"converters/migration/","title":"Migration","text":" SuspendResponseConverter
 override suspend fun <RequestType> wrapSuspendResponse(\ntypeData: TypeData,\nrequestFunction: suspend () -> Pair<TypeInfo, HttpResponse>,\nktorfit: Ktorfit\n): Any {\nreturn object : Call<RequestType> {\noverride fun onExecute(callBack: Callback<RequestType>) {\n\nktorfit.httpClient.launch {\nval deferredResponse = async { requestFunction() }\n\nval (data, response) = deferredResponse.await()\n\ntry {\nval res = response.call.body(data)\ncallBack.onResponse(res as RequestType, response)\n} catch (ex: Exception) {\ncallBack.onError(ex)\n} } } } }\n\noverride fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {\nreturn typeData.qualifiedName == \"de.jensklingenberg.ktorfit.Call\"\n}\n
Equivalent with converter factory:
public class CallConverterFactory : Converter.Factory {\n\noverride fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == Call::class) {\nreturn object: Converter.SuspendResponseConverter<HttpResponse, Call<Any?>> {\noverride suspend fun convert(response: HttpResponse): Call<Any?> {\n\nreturn object : Call<Any?> {\noverride fun onExecute(callBack: Callback<Any?>) {\nktorfit.httpClient.launch {\ntry {\nval data = response.call.body(typeData.typeArgs.first().typeInfo)\ncallBack.onResponse(data!!, response)\n} catch (ex: Exception) {\ncallBack.onError(ex)\n} } } } } } }\nreturn null\n}\n}\n
ResponseConverter
override fun <RequestType> wrapResponse(\ntypeData: TypeData,\nrequestFunction: suspend () -> Pair<TypeInfo, HttpResponse?>,\nktorfit: Ktorfit\n): Any {\nreturn object : Call<RequestType> {\noverride fun onExecute(callBack: Callback<RequestType>) {\n\nktorfit.httpClient.launch {\nval deferredResponse = async { requestFunction() }\n\ntry {\nval (info, response) = deferredResponse.await()\nval data = response!!.body(info) as RequestType\ncallBack.onResponse(data, response)\n} catch (ex: Exception) {\ncallBack.onError(ex)\n}\n\n}\n}\n\n}\n}\n\noverride fun supportedType(typeData: TypeData, isSuspend: Boolean): Boolean {\nreturn typeData.qualifiedName == \"de.jensklingenberg.ktorfit.Call\"\n}\n
Equivalent with converter factory:
public class CallConverterFactory : Converter.Factory {\noverride fun responseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.ResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == Call::class) {\nreturn object : Converter.ResponseConverter<HttpResponse, Call<Any?>> {\n\noverride fun convert(getResponse: suspend () -> HttpResponse): Call<Any?> {\nreturn object : Call<Any?> {\noverride fun onExecute(callBack: Callback<Any?>) {\nktorfit.httpClient.launch {\ntry {\nval response = getResponse()\n\nval data = response.call.body(typeData.typeArgs.first().typeInfo)\n\ncallBack.onResponse(data, response)\n} catch (ex: Exception) {\nprintln(ex)\ncallBack.onError(ex)\n} } } } } } }\nreturn null\n}\n}\n
"},{"location":"converters/requestparameterconverter/","title":"RequestParameterConverter","text":"
@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsById(@RequestType(Int::class) @Path(\"postId\") postId: String): List<Comment>\n

You can set RequestType at a parameter with a type to which the parameter should be converted.

Then you need to implement a Converter factory with a RequestParameterConverter.

class StringToIntRequestConverterFactory : Converter.Factory {\noverride fun requestParameterConverter(\nparameterType: KClass<*>,\nrequestType: KClass<*>\n): Converter.RequestParameterConverter? {\nreturn object : Converter.RequestParameterConverter {\noverride fun convert(data: Any): Any {\n//convert the data\n}\n}\n}\n}\n
ktorfit.converterFactories(StringToIntRequestConverterFactory())\n
"},{"location":"converters/responseconverter/","title":"ResponseConverter","text":"

You only need ResponseConverters for cases where you can\u2019t use a suspend function in your interface. For every other case you want SuspendResponseConverter

Because Ktor relies on Coroutines by default your functions need to have the suspend modifier.

Let\u2019s say you have API endpoint to get a list of comments and you want to get them as Flow.

Ktorfit already has a converter for Flow, but it\u2019s used as an example

@GET(\"/user\")\nfun getUser(): Flow<List<Commment>>\n

Now you need a converter that can convert the HTTPResponse and return a Flow. Create a class that extends Converter.Factory

class FlowConverterFactory : Converter.Factory {\n}\n

Next you need to overwrite responseConverter()

override fun responseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.ResponseConverter<HttpResponse, *>? {\n

Inside responseConverter you can decide if you want to return a converter. In our case we want a converter for the type Flow. We can check that case with the typeData that we get as a parameter.

override fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif (typeData.typeInfo.type == Flow::class) {\n...\n}\nreturn null\n}\n

Next we create the ResponseConverter:

if (typeData.typeInfo.type == User::class) {\nval requestType = typeData.typeArgs.first()\n\nreturn object : Converter.ResponseConverter<HttpResponse, Flow<Any>> {\noverride fun convert(getResponse: suspend () -> HttpResponse): Flow<Any> {\nreturn flow {\ntry {\nval response = getResponse()\nif (requestType.typeInfo.type == HttpResponse::class) {\nemit(response)\n} else {\nval data = ktorfit.nextSuspendResponseConverter(this@FlowConverterFactory, requestType)\n?.convert(response)\nemit(data)\n}\n} catch (exception: Exception) {\nthrow exception\n}\n}\n}\n}\n}\n

Inside of convert we get the HttpResponse from getResponse(). We use nextSuspendResponseConverter to find the next converter that can convert the response. Then we put the converted response in the Flow and return it.

Finally, add your converter factory to the Ktorfit Builder

Ktorfit.Builder().converterFactories(FlowConverterFactory()).baseUrl(\"foo\").build()\n
"},{"location":"converters/responseconverter/#flow","title":"Flow","text":"

Ktorfit has support for Kotlin Flow. You need add the FlowConverterFactory() to your Ktorfit instance.

ktorfit.converterFactories(FlowConverterFactory())\n
@GET(\"comments\")\nfun getCommentsById(@Query(\"postId\") postId: String): Flow<List<Comment>>\n

Then you can drop the suspend modifier and wrap your return type with Flow<>

"},{"location":"converters/responseconverter/#call","title":"Call","text":"
ktorfit.converterFactories(CallConverterFactory())\n
@GET(\"people/{id}/\")\nfun getPersonById(@Path(\"id\") peopleId: Int): Call<People>\n
exampleApi.getPersonById(3).onExecute(object : Callback<People> {\noverride fun onResponse(call: People, response: HttpResponse) {\n//Do something with Response\n}\n\noverride fun onError(exception: Exception) {\n//Do something with exception\n}\n})\n

You can use Call to receive the response in a Callback."},{"location":"converters/suspendresponseconverter/","title":"SuspendResponseConverter","text":"

Let`s say you have a function that requests a list of comments

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): List<Comment>\n

But now you want to directly wrap your comment list in your data holder class e.g. \u201cMyOwnResponse\u201d

sealed class MyOwnResponse<T> {\ndata class Success<T>(val data: T) : MyOwnResponse<T>()\nclass Error(val ex:Throwable) : MyOwnResponse<Nothing>()\n\ncompanion object {\nfun <T> success(data: T) = Success(data)\nfun error(ex: Throwable) = Error(ex)\n}\n}\n

To enable that, you have to implement a SuspendResponseConverter. This class will be used to wrap the Ktor response inside your wrapper class.

class MyOwnResponseConverterFactory : Converter.Factory{\n\noverride fun suspendResponseConverter(\ntypeData: TypeData,\nktorfit: Ktorfit\n): Converter.SuspendResponseConverter<HttpResponse, *>? {\nif(typeData.typeInfo.type == MyOwnResponse::class) {\n\nreturn object : Converter.SuspendResponseConverter<HttpResponse, Any> {\noverride suspend fun convert(response: HttpResponse): Any {\nreturn try {\nMyOwnResponse.success(response.body(typeData.typeArgs.first().typeInfo))\n} catch (ex: Throwable) {\nMyOwnResponse.error(ex)\n}\n}\n}\n}\nreturn null\n}\n}\n

You can then add the ResponseConverter to your Ktorfit object.

ktorfit.converterFactories(MyOwnResponseConverterFactory())\n

Now add MyOwnResponse to your function

@GET(\"posts/{postId}/comments\")\nsuspend fun getCommentsByPostId(@Path(\"postId\") postId: Int): MyOwnResponse<List<Comment>>\n

"},{"location":"fundamentals/scope/","title":"Scope of Ktorfit","text":"

The goal of Ktorfit is to provide a similar developer experience like Retrofit for Kotlin Multiplatform projects. It`s not a 100% drop-in replacement for Retrofit. It uses Ktor clients because they are available on nearly every compile target of KMP. Every feature should be implemented so that it works on all platforms that Ktor supports. Before a new functionality is added to Ktorfit, it should be checked if there is already a Ktor plugin for it which solves the same problem.

"}]} \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index 34f9427ac..a47f55940 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,92 +2,92 @@ https://github.com/Foso/Ktorfit/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/CHANGELOG/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/License/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/architecture/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/configuration/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/development/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/installation/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/quick-start/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/requests/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/responseconverter/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/suspendresponseconverter/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/converters/converters/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/converters/example1/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/converters/migration/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/converters/requestparameterconverter/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/converters/responseconverter/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/converters/suspendresponseconverter/ - 2023-08-02 + 2023-08-04 daily https://github.com/Foso/Ktorfit/fundamentals/scope/ - 2023-08-02 + 2023-08-04 daily \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index aa010a8ee..1ae0dd790 100644 Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ