Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A path parameter is a portion of the request URL matching a particular pattern. As such, there are character limitations on what can be specified as a path param - in particular any special characters need to be URL encoded. This applies the same across any kind of request (<em>GET</em>, <em>POST</em>, <em>PUT</em>, <em>DELETE</em>). </p> <p>As a general rule, you should restrict your path parameters to simple values like identifiers, or resource endpoints - more complex data should be passed to the REST service via request parameters or the request body itself. Here's a mixed approach that passes an entity identifier as a path parameter, and the entity data in the request body:</p> <pre><code>@Path("/contacts/{id}") @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateContact(@PathParam final String contactId, Contact contact) { } </code></pre> <p>In the above example, the <em>contactId</em> is obtained as a path parameter and the contact is serialized automatically from the request body.</p> <p>What I described above are <strong><em>general</em></strong> rules. Now as to the specifics of your case, one thing I notice in your code is that you don't actually define any path parameters. Remember that they have to be defined as part of your <code>@Path</code> annotation, before being consumed in your REST method:</p> <pre><code>@Path("/method/{obj1}/{obj2}") public ResponseObject method(@Context Request request, @PathParam("obj1") Object obj1, @PathParam("obj2") String obj2) { } </code></pre> <p>With the above changes your parameters should no longer show up as being null, assuming you have properly encoded the URL on the client side.</p> <hr> <p><strong>* EDIT *</strong></p> <p>Based on your comment, I see you need to become more familiar with the JAX-RS specification and the various parameter types. I recommend reading through the <a href="http://docs.jboss.org/resteasy/docs/2.0.0.GA/userguide/html_single/index.html">RESTEasy JAX-RS Documentation</a>. It has some vendor specific implementation details but all in all is an excellent guide to JAX-RS.</p> <hr> <h3>@PathParam</h3> <p><em><strong>Purpose</em></strong>: Used to inject a portion of the request URL into a variable. Note that URL parameters are <em>not</em> considered part of the URL.</p> <p><em><strong>Example</em></strong>: Given the URL <em><a href="http://services.example.com/contacts/20578">http://services.example.com/contacts/20578</a></em>, I can define:</p> <pre><code>@Path("/contacts/{id}") </code></pre> <p>From which I can inject a <code>@PathParam("id")</code>.</p> <pre><code>public Response getContact(@PathParam("id") final String identifier); </code></pre> <p>This works for <em>any</em> kind of HTTP request (<em>GET</em>, <em>POST</em>, <em>PUT</em>, <em>DELETE</em>).</p> <hr> <h3>@QueryParam</h3> <p><em><strong>Purpose</em></strong>: Used to inject a portion of the query string or form encoded data into a variable. The query string is that portion of your URL after the <code>?</code>. Form encoded data are the URL encoded name/value pair data passed in the body of an HTTP request, when the request type is <em>application/x-www-form-urlencoded</em>. Typically, query parameters are passed as part of the URL string for GET requests, and in the request body for POST requests.</p> <p>Example: Given the URL <a href="http://services.example.com/contacts?group=Business">http://services.example.com/contacts?group=Business</a>, I can inject a <code>@QueryParam("group")</code></p> <pre><code>public Response getContactsInGroup(@QueryParam("group") final String groupName); </code></pre> <p>It's atypical to use query parameters with a POST request, but it is possible if the request type is <em>application/x-www-form-urlencoded</em>:</p> <pre><code>@POST @Path("/contacts") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response createContact(@QueryParam("contact") final Contact contactData, @QueryParam("metadata") final String metaData); </code></pre> <p>These are just high level examples, please read through the <a href="http://docs.jboss.org/resteasy/docs/2.0.0.GA/userguide/html_single/index.html#_PathParam">documentation</a> I linked to get a better example of how each parameter type works, and when to use which one.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload