Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.web.client.RestClient
import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestClient
import org.springframework.web.util.UriComponentsBuilder
import org.springframework.util.LinkedMultiValueMap

{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}open class ApiClient(protected val client: RestClient) {
Expand Down Expand Up @@ -35,12 +36,13 @@ import org.springframework.util.LinkedMultiValueMap
private fun <I> RestClient.method(requestConfig: RequestConfig<I>)=
method(HttpMethod.valueOf(requestConfig.method.name))

private fun <I> RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>) =
uri(requestConfig.path) { builder ->
builder
.queryParams(LinkedMultiValueMap(requestConfig.query))
.build(requestConfig.params)
private fun <I> RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>): RestClient.RequestBodySpec {
val uriComponentsBuilder = UriComponentsBuilder.fromPath(requestConfig.path)
requestConfig.query.forEach { key, values ->
uriComponentsBuilder.queryParam(key, "{$key}")
}
return uri(uriComponentsBuilder.encode().buildAndExpand(requestConfig.query + requestConfig.params).toUri())
}

private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.web.client.RestClient
import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestClient
import org.springframework.web.util.UriComponentsBuilder
import org.springframework.util.LinkedMultiValueMap

open class ApiClient(protected val client: RestClient) {
Expand Down Expand Up @@ -35,12 +36,13 @@ open class ApiClient(protected val client: RestClient) {
private fun <I> RestClient.method(requestConfig: RequestConfig<I>)=
method(HttpMethod.valueOf(requestConfig.method.name))

private fun <I> RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>) =
uri(requestConfig.path) { builder ->
builder
.queryParams(LinkedMultiValueMap(requestConfig.query))
.build(requestConfig.params)
private fun <I> RestClient.RequestBodyUriSpec.uri(requestConfig: RequestConfig<I>): RestClient.RequestBodySpec {
val uriComponentsBuilder = UriComponentsBuilder.fromPath(requestConfig.path)
requestConfig.query.forEach { key, values ->
uriComponentsBuilder.queryParam(key, "{$key}")
}
return uri(uriComponentsBuilder.encode().buildAndExpand(requestConfig.query + requestConfig.params).toUri())
}

private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
Expand Down
Loading