How RESTful Web Services Extract Input Parameters
In this article i will show you how a RESTful web service will extract input parameters from the client request. We have different ways of sending input values to the rest services, and RESTful web service extract those details based upon the client URL pattern. In JAX-RS we can use the following annotations to extract the input values sent by the client.
@PathParam,@QueryParam,@MatrixParam are parameter annotations which allows us to map variable URI path fragments into your method call. Confused ? 🙂 In simple words, these three annotations will come into picture in case if we are passing the input values to the restful service through the URL. After that Rest service will extract those values by using these annotations. Regarding @FormParam, restful web service will use this annotation to retrieve the values sent by the client through some HTML/JSP form.
@PathParam URL Syntax
http://localhost:7001/<Rest Service Name>/rest/customers/100/Java4s
Did you observe the two parameters appear in the end of the above URL [100 & Java4s], which are separated by forward slash(/) are called as path parameters, as of now just remember the syntax, going forward i will give you an example on each annotation.
@QueryParam URL Syntax
If the client sends an input in the form of query string in the URL, then those parameters are called as Query Parameters. If you observe the above syntax, client passing 2 parameters 100 and Java4s started after question mark (?) symbol and each parameter is separated by & symbol, those parameters are called as query parameters.
@MatrixParam URL Syntax
Matrix parameters are another way defining the parameters to be added to URL. If you observe the above syntax, client is passing two parameters each are separated by semicolon, these parameters are called as matrix parameters. Remember these parameters may appear any where in the path.
@FormParam URL Syntax
Finally form parameters, if we have a HTML form having two input fields and submit button. Lets client enter those details and submit to the RESTful web service. Then the rest service will extract those details by using this @FormParam annotation.
For now just remember these consents, going forward i will give you an example on each annotation.
You Might Also Like
::. About the Author .::