Optional parameter in @PathParam annotation Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Optional parameter in @PathParam annotation without wasting too much if your time.

The question is published on by Tutorial Guruji team.

We are facing issue related with making a path parameter optional.

original URL /expire/{token}

What we are trying to do is have the same service work for the URL’s below.

   1. /expire/{token}
   2. /expire

Ex:- @Path("/expire/{token}")

We have already applied other solutions from SO,but no luck so far.


Logically, it doesn’t seem to make sense to have it optional. Your URI should handle the type of request it’s supposed to do. But, I came across a post to make the @PathParam to be optional with a small hack using regular expressions.


I would go with having separate endpoint method in Controller where it can pass the call to your services with optional parameter.

We are here to answer your question about Optional parameter in @PathParam annotation - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji