Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path Address in RESTful Web Service using Jersey

I have a question about Restful Web Service in java

I am completely familiar with the information in the link and how to implement a Jersey service.

The path which I use is always something like this:

SERVER_ADDRESS/task/users/{username}/

SERVER_ADDRESS can be like 192.168.1.104:8080 and {username} is @PathParam

look at this address:

SERVER_ADDRESS/task/users/{username}/tasks?top=n

My question is about the end : tasks?top=n

I saw pretty much example with this kind of address at the end, but I don't know what is the usage of them in compare with for instance @PathParam.

How can we create such an idea in Jersey? And what is the usage of this kind of address?

like image 451
Ali Avatar asked Nov 23 '25 03:11

Ali


2 Answers

To get at tasks, your must wrap it in {} in the @Path and use a @PathParam to get it.

For top=n use a @QueryParam("top") int (if int is the type of top).

All this is described in the easy-to-read JAX-RS Spec, version 1.1.

Possible uses for @QueryParam are

  • when you are passing some filters to the list you are goint to get back. These filters may be optonal and does fit as path params.

  • Giving pagination limits like start and offset as a valid case.

  • Passing a list of attributes that you need. For performance reasons you may not want the full response.

like image 45
basiljames Avatar answered Nov 24 '25 18:11

basiljames



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!