jax-rs @PathParam example

Hi, till now we’ve seen how we can retrieve a resource using GET request and post data using POST request. Many time we need to get some resource based on certain parameters. i.e. It is a GET request but we send some information through urls. Jax-rs @PathParam example will demonstrate how to do it using @PathParam annotations.

JAX-RS @PathParam Example:

Referring from the same hello world example, we are going to create a jax-rs @PathParam example.

Points to note here,

  • @Path(“/sayHello/{name}”) means that after path “/sayHello”, it is expecting a variable value to which it will call “name”
  • @PathParam(“name”) annotated for method argument says that value picked from @Path should be applied to name variable in method argument.

Now deploy his jax-rs @PathParam application in jboss and visit below url.

http://localhost:8080/JAX-RS_examples/rest/HelloWorld/sayHello/prasad

It will print

Hello prasad

I hope the jax-rs @PathParam example helps understand the concept.