java - 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("");
推荐阅读
- amazon-web-services - 从 AWS 托管批处理作业中获取实例类型
- c# - 为什么我不能指定从 AC# 函数返回的数组的大小?
- c - 为什么我们没有ccflags-m,而是ccflags-y?
- c# - Visual Studio 2019 历史调试不适用于 Fip
- powershell - 如何从另一台机器上的另一个 IIS 实例导入 IIS 处理程序映射?
- c# - BItwise Operator,左移和右移如何工作
- java - android moto G (3rd Generation) 中的 DateFormat 问题,登录日期
- excel - 复制并粘贴到下一个空行
- javascript - 如何从数组中找到对象的数组属性值的总和?
- r - 从逐步回归的所有模型中提取 AIC