/* * Copyright 2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * 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 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" 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. */ package org.springframework.kotlin.coroutine.web.client import org.springframework.core.ParameterizedTypeReference import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod import org.springframework.http.RequestEntity import org.springframework.http.ResponseEntity import org.springframework.kotlin.coroutine.NewThreadCoroutineDispatcher import org.springframework.kotlin.coroutine.proxy.DefaultCoroutineProxyConfig import org.springframework.kotlin.coroutine.proxy.createCoroutineProxy import org.springframework.web.client.RequestCallback import org.springframework.web.client.ResponseExtractor import org.springframework.web.client.RestOperations import org.springframework.web.client.RestTemplate import java.net.URI import kotlin.coroutines.CoroutineContext interface CoroutineRestOperations { suspend fun postForObject(url: String, request: Any?, responseType: Class?, vararg uriVariables: Any?): T suspend fun postForObject(url: String, request: Any?, responseType: Class?, uriVariables: Map): T suspend fun postForObject(url: URI, request: Any?, responseType: Class?): T suspend fun put(url: String, request: Any?, vararg uriVariables: Any?) suspend fun put(url: String, request: Any?, uriVariables: Map) suspend fun put(url: URI, request: Any?) suspend fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: Class?, vararg uriVariables: Any?): ResponseEntity suspend fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: Class?, uriVariables: Map): ResponseEntity suspend fun exchange(url: URI, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: Class?): ResponseEntity suspend fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: ParameterizedTypeReference, vararg uriVariables: Any?): ResponseEntity suspend fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: ParameterizedTypeReference, uriVariables: Map): ResponseEntity suspend fun exchange(url: URI, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: ParameterizedTypeReference): ResponseEntity suspend fun exchange(requestEntity: RequestEntity<*>?, responseType: Class?): ResponseEntity suspend fun exchange(requestEntity: RequestEntity<*>?, responseType: ParameterizedTypeReference): ResponseEntity suspend fun getForEntity(url: String, responseType: Class?, vararg uriVariables: Any?): ResponseEntity suspend fun getForEntity(url: String, responseType: Class?, uriVariables: Map): ResponseEntity suspend fun getForEntity(url: URI, responseType: Class?): ResponseEntity suspend fun headForHeaders(url: String, vararg uriVariables: Any?): HttpHeaders suspend fun headForHeaders(url: String, uriVariables: Map): HttpHeaders suspend fun headForHeaders(url: URI): HttpHeaders suspend fun getForObject(url: String, responseType: Class?, vararg uriVariables: Any?): T suspend fun getForObject(url: String, responseType: Class?, uriVariables: Map): T suspend fun getForObject(url: URI, responseType: Class?): T suspend fun execute(url: String, method: HttpMethod, requestCallback: RequestCallback?, responseExtractor: ResponseExtractor?, vararg uriVariables: Any?): T suspend fun execute(url: String, method: HttpMethod, requestCallback: RequestCallback?, responseExtractor: ResponseExtractor?, uriVariables: Map): T suspend fun execute(url: URI, method: HttpMethod, requestCallback: RequestCallback?, responseExtractor: ResponseExtractor?): T suspend fun postForEntity(url: String, request: Any?, responseType: Class?, vararg uriVariables: Any?): ResponseEntity suspend fun postForEntity(url: String, request: Any?, responseType: Class?, uriVariables: Map): ResponseEntity suspend fun postForEntity(url: URI, request: Any?, responseType: Class?): ResponseEntity suspend fun optionsForAllow(url: String, vararg uriVariables: Any?): Set suspend fun optionsForAllow(url: String, uriVariables: Map): Set suspend fun optionsForAllow(url: URI): Set suspend fun patchForObject(url: String, request: Any?, responseType: Class?, vararg uriVariables: Any?): T suspend fun patchForObject(url: String, request: Any?, responseType: Class?, uriVariables: Map): T suspend fun patchForObject(url: URI, request: Any?, responseType: Class?): T suspend fun postForLocation(url: String, request: Any?, vararg uriVariables: Any?): URI suspend fun postForLocation(url: String, request: Any?, uriVariables: Map): URI suspend fun postForLocation(url: URI, request: Any?): URI suspend fun delete(url: String, vararg uriVariables: Any?) suspend fun delete(url: String, uriVariables: Map) suspend fun delete(url: URI) companion object { operator fun invoke(restOperations: RestOperations = RestTemplate(), context: CoroutineContext? = NewThreadCoroutineDispatcher): CoroutineRestOperations = createCoroutineProxy(CoroutineRestOperations::class.java, restOperations, DefaultCoroutineProxyConfig(context)) } }