Senthil
Senthil

Reputation: 523

Call POST method in RESTFul Web service

I want to create a sample RESTful web service in java which involves all the four CRUD operations and I deployed it in tomcat. I used JAX-RS (Jersey) library to implement this in java. As of now , I can call the GET method to retrieve the list of records and display it. But I don know how to call the POST, PUT and DELETE method. Can anyone tell how to call those methods ?

Upvotes: 1

Views: 10400

Answers (1)

MStodd
MStodd

Reputation: 4746

Give this a shot, you can extract the key/value pairs on the server side pretty easily:

ClientConfig config = new DefaultClientConfig();
com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(config);

MultiValueMap formData = new MultiValueMapImpl();
formData.add("key", "value");

WebResource resource = client.resource("http://path/to/resource");
ClientResponse response = resource.type("application/x-www-form-urlencoded").post(ClientResponse.class, formData);

Upvotes: 1

Related Questions