jax-rs @PathParam example

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

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.

HelloWorldService.java

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.

 

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

One thought on “jax-rs @PathParam example

Leave a Reply

Your email address will not be published. Required fields are marked *