Eerik Sven Puudist
Eerik Sven Puudist

Reputation: 2348

Quarkus: request to URL given as string

I want to make an HTTP request with Quarkus. However, the target URL is not known at compilation time, it will be composed from different parts at runtime.

Quarkus provides a way to build static REST clients like this:

@Path("/v2")
@RegisterRestClient
public interface CountriesService {

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

However, I am loking for something like the Python requests package:

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

I am building the application in Kotlin, so all Java and Kotlin libraries should work.

What should I use?

Upvotes: 1

Views: 2408

Answers (1)

Ken
Ken

Reputation: 835

With the MP REST Client defined in an interface, you can use the programmatic client creation API:

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

Upvotes: 3

Related Questions