PathParam for Jersey WebResource
Asked Answered
M

1

6

I'm working on a task to create a Jersey client. I'm using Jersey 1.18. The target URL looks like below.

https://api.test.com/test/{id}?param1=test1&param2=test2

I need to add a PathParam to my WebResource to call this URL. I see an option to add the QueryParam but not for PathParam. My code looks something like this.

Client client = Client.create();
WebResource webResource = client.resource("https://api.test.com/test/{id}")
  .queryParam("param1", "test1")
  .queryParam("param2", "test2");

Can anyone please help me with this?

Mugwump answered 13/6, 2016 at 19:38 Comment(0)
G
4

You need the path method from WebResource...

final String myId = "1234";
Client client = Client.create();
WebResource webResource = client.resource("https://api.test.com/test")
                                .path(myId)
                                .queryParam("param1", "test1")
                                .queryParam("param2", "test2");
Gasolier answered 13/6, 2016 at 22:24 Comment(1)
@Jane was referring to a path parameter and not a query parameterChairmanship

© 2022 - 2024 — McMap. All rights reserved.