Quarkus:请求以字符串形式给出的URL



我想用Quarkus发出HTTP请求。但是,目标 URL 在编译时是未知的,它将在运行时由不同的部分组成。

Quarkus 提供了一种构建静态 REST 客户端的方法,如下所示:

@Path("/v2")
@RegisterRestClient
public interface CountriesService {
@GET
@Path("/name/{name}")
@Produces("application/json")
Set<Country> getByName(@PathParam String name);
}

但是,我正在寻找类似 Pythonrequests包的东西:

url = 'https://stackoverflow.com/questions/ask'
response = requests.get(url)

我正在 Kotlin 中构建应用程序,因此所有 Java 和 Kotlin 库都应该可以工作。

我应该使用什么?

在接口中定义 MP REST 客户端后,您可以使用编程客户端创建 API:

CountriesService remoteApi = RestClientBuilder.newBuilder()
.baseUri("created at runtime url")
.build(CountriesService.class);
remoteApi.getByName("");

最新更新