我想用Quarkus发出HTTP请求。但是,目标URL在编译时未知,它将在运行时由不同部分组成。
Quarkus提供了一种构建静态REST客户端的方法,如下所示:
@Path("/v2")
@RegisterRestClient
public interface CountriesService {
@GET
@Path("/name/{name}")
@Produces("application/json")
Set<Country> getByName(@PathParam String name);
}
但是,我希望找到类似Python requests
包的东西:
url = 'https://stackoverflow.com/questions/ask'
response = requests.get(url)
我正在Kotlin中构建应用程序,因此所有Java和Kotlin库都应该工作。
我应该使用什么?
答案 0 :(得分:2)
在接口中定义了MP REST客户端后,您可以使用程序化客户端创建API:
CountriesService remoteApi = RestClientBuilder.newBuilder()
.baseUri("created at runtime url")
.build(CountriesService.class);
remoteApi.getByName("");