0

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.

Rakesh
  • 58
  • 1
  • 6
  • Careful in your research. Path Parameters are things like `http://machine/this;foo=1/is;bar=2/what;cue=3/path-params-look-like` (it's part of the URI and HTTP specs) – Joakim Erdfelt Jun 16 '21 at 10:08
  • @JoakimErdfelt I implied like JAX-RS PathParam in my question where we get the value from url using this annotation e.g if the url is /api/users/{id} the in a JAX-RS resource we can get the value of {id} using the annotation PathParam. I should have provided the JAX-RS reference, sorry for the inconvenience. – Rakesh Jun 16 '21 at 12:14
  • What you are asking for is actually "URI Template" (level 1 support) - https://datatracker.ietf.org/doc/html/rfc6570 – Joakim Erdfelt Jun 16 '21 at 12:30

0 Answers0