<commit_before>package io.udash
package rest

import com.avsystem.commons._
import com.avsystem.commons.annotation.explicitGenerics
import com.avsystem.commons.meta.Mapping
import com.softwaremill.sttp.Uri.QueryFragment.KeyValue
import com.softwaremill.sttp.Uri.QueryFragmentEncoding
import com.softwaremill.sttp._
import io.udash.rest.DefaultSttpBackend.backend
import io.udash.rest.raw._

object DefaultRestClient {
  @explicitGenerics def apply[RestApi: RawRest.AsRealRpc : RestMetadata](baseUri: String): RestApi =
    RawRest.fromHandleRequest[RestApi](asHandleRequest(baseUri))

  def asHandleRequest(baseUri: String): RawRest.HandleRequest =
    asHandleRequest(uri"$baseUri")

  private def toSttpRequest(baseUri: Uri, request: RestRequest): Request[String, Nothing] = {
    val uri = baseUri |>
      (u => u.copy(path = u.path ++
        request.parameters.path.map(_.value))) |>
      (u => u.copy(queryFragments = u.queryFragments ++
        request.parameters.query.iterator.map {
          case (k, QueryValue(v)) => KeyValue(k, v, QueryFragmentEncoding.All, QueryFragmentEncoding.All)
        }.toList
      ))

    val contentTypeHeader = request.body.mimeTypeOpt.map {
      mimeType => (HeaderNames.ContentType, s"$mimeType;charset=utf-8")<commit_msg>scaladoc<commit_after>package io.udash
package rest

import com.avsystem.commons._
import com.avsystem.commons.annotation.explicitGenerics
import com.avsystem.commons.meta.Mapping
import com.softwaremill.sttp.Uri.QueryFragment.KeyValue
import com.softwaremill.sttp.Uri.QueryFragmentEncoding
import com.softwaremill.sttp._
import io.udash.rest.DefaultSttpBackend.backend
import io.udash.rest.raw._

object DefaultRestClient {
  @explicitGenerics def apply[RestApi: RawRest.AsRealRpc : RestMetadata](baseUri: String): RestApi =
    RawRest.fromHandleRequest[RestApi](asHandleRequest(baseUri))

  /**
    * Creates a [[io.udash.rest.raw.RawRest.HandleRequest HandleRequest]] function which sends REST requests to
    * a specified base URI using default HTTP client implementation (sttp).
    */
  def asHandleRequest(baseUri: String): RawRest.HandleRequest =
    asHandleRequest(uri"$baseUri")

  private def toSttpRequest(baseUri: Uri, request: RestRequest): Request[String, Nothing] = {
    val uri = baseUri |>
      (u => u.copy(path = u.path ++
        request.parameters.path.map(_.value))) |>
      (u => u.copy(queryFragments = u.queryFragments ++
        request.parameters.query.iterator.map {
          case (k, QueryValue(v)) => KeyValue(k, v, QueryFragmentEncoding.All, QueryFragmentEncoding.All)
        }.toList
      ))

    val contentTypeHeader = request.body.mimeTypeOpt.map {
      mimeType => (HeaderNames.ContentType, s"$mimeType;charset=utf-8")
{'fraction_non_alphanumeric': 0.11448427212874908, 'fraction_numerical': 0.000731528895391368, 'mean_word_length': 4.437375745526839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3831558', 'n_tokens_mistral': 855, 'n_tokens_neox': 830, 'n_words': 155}