Home/Tutorials/RESTful Web Services/Path Params in GET Request
RESTful Web Services2 min read

Path Params in GET Request

In this tutorial you will see how to use path params in GET request in a RESTful web service, written in Java and deployed on Apache Tomcat Service.

Path Params in GET Rest Request

In JAX-RS, you can use @PathParam annotation to extract the parameter from the request URI and map it to any method.

Suppose the client wants the information for student with the roll number 1 or 2 and not for all the students. In such situation, we can use the @PathParam to map this to a method which will return only the requested student's record.

@GET
@Produces(MediaType.APPLICATION_XML)
@Path("/{rollno}")
public Student getStudentWithRollNo(@PathParam("rollno")int rollNo)
{
	Student student = studentService.getStudentWithRollNo(rollNo);
	return student;
}

The @PathParam annotation will map the rollno from the resource URI to the rollNo argument of the method.

Path Params in GET Request

Path Params in GET Request

Thus with the @PathParam annotation we can map the request URI parameters with the Java method arguments.



INTERACTIVE SIMULATION CHALLENGE+250 XP
Workbench Verification

Ready to test "Path Params in GET Request" in production?

See how RESTful Web Services algorithms and server loops perform under 100k req/s traffic spikes.

Simulator: SysDesign Ops Simulator