Eri*_*ria 7 java resteasy quarkus
我需要从 Quarkus 应用程序发送 HTTP 请求。按照本指南,我有这个 RestClient:
@Path("/v1")
@RegisterRestClient
public interface CountriesService {
@GET
@Path("/name/{name}")
Set<Country> getByName(@PathParam String name);
}
Run Code Online (Sandbox Code Playgroud)
在Path注释中,我可以配置路径。但根据本段,要调用的域/url 是在配置文件中定义的。
# Your configuration properties
org.acme.rest.client.CountriesService/mp-rest/url=https://restcountries.eu/rest #
org.acme.rest.client.CountriesService/mp-rest/scope=javax.inject.Singleton #
Run Code Online (Sandbox Code Playgroud)
就我而言,我需要在运行时以编程方式定义此 URL,因为我将其作为回调 URL 接收。
有没有办法做到这一点?
Quarkus Rest Client 和 Quarkus Rest Client Reactive 实现了 MicroProfile Rest 规范,因此允许以编程方式创建客户端存根RestClientBuilder,例如:
public class SomeService {
public Response doWorkAgainstApi(URI apiUri, ApiModel apiModel) {
RemoteApi remoteApi = RestClientBuilder.newBuilder()
.baseUri(apiUri)
.build(RemoteApi.class);
return remoteApi.execute(apiModel);
}
}
Run Code Online (Sandbox Code Playgroud)
您无法通过使用@RegisterRestClient 注释创建的客户端来实现此目的