users@jersey.java.net

Re: [Jersey] Re: New to REST - How to send data for POST method

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 1 Sep 2010 17:39:16 +0200

On Sep 1, 2010, at 3:50 PM, piranha wrote:

>
> Actually my problem is, we dont use any kind of HTML Forms in our
> application.
>

It does not matter. You can send application/x-www-form-urlencoded
from any client that supports the form-based encoding. For example
with curl:

   curl -d x=z http://localhost:8080/myapp

The above will send a POST request with a content-type of "application/
x-www-form-urlencoded" and a request entity of: "x=z".

Or you can send XML or JSON or property name/value pairs, it is up to
you.


> So, i cant send the data using HTTP form or any Jersey client. i
> guess ineed
> to usePUT method.
>

In this case it does not matter whether it is PUT or POST except for
the fact that PUT has semantics and POST does not.

I highly recommend the RESTful Web services book as a good source to
understand REST and HTTP:

   http://oreilly.com/catalog/9780596529260


> Is there any way, i can send the data by adding it to the request URL?
>
> http://RestApp/Resource/add/id/fName/lName
>
> where id, fName, lName is the data i need to add new content int
> othe DB.

I would not recommend doing that, placing such information in the URI
to update state can break the contract of GET. URIs should identify
resources whose current state can be obtained using GET and can be
modified using PUT, POST or DELETE.

Jersey comes with a bunch of samples, i recommend having a play with
them:

   http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.3/jersey-samples-1.3-project.zip

Paul.