URI Template support in Jetty HttpClient v11.x

129 Views Asked by At

I have just started using the Jetty HttpClient v11 and it is great. However, inherent support for path params or route params seem to be missing, although it has a nice way to add query params.

Path param example:

https://localhost:8080/api/users/{id}

Not sure if it is there and I missed it but I am seeking a way to achieve it. So, if someone has done it and created a well tested small (zero external dependencies) utility/library for that, then please point it out to me.

Update:

Just to provide a context here like what am I trying to achieve.

Consider this JAX-RS resource method.

@Path("/users/{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public User getUser(@PathParam("id") String id) {
    return this.userRepository.findOneById(id);
}

We can get the value of {id} using the annotation @PathParam.

Similarly I wanted to provide a way in the RestClient I wrote on top of Jetty HttpClient where consumer could do something.

Request jettyRequest = jettyClient.newRequest("https://apiserver.com/api/users/{id}")
            .pathParam("id", 1234)
            .method("GET");

I was just looking for the same in HttpClient, I know this can be done before passing the URI to the newRequest method here.

0

There are 0 best solutions below