POST Attributes with Restlet 2

April 28th, 2011 by nils

Since I keep forgetting how to do this, here is a code snippet to POST parameters to some URL using Restlet 2:

Client restletClient = new Client(new Context(), Protocol.HTTP);
Reference resourceRef = new Reference("THE URL...");
resourceRef.addQueryParameter("key", "value");
Request request = new Request(Method.POST, resourceRef);

Response response = restletClient.handle(request);
String responseAsText = response.getEntityAsText();

Oh, and you’ll want to add the following dependencies to your maven pom.xml (if you’re using maven…):

...
<dependency>
  <groupId>org.restlet.jee</groupId>
  <artifactId>org.restlet</artifactId>
</dependency>
<dependency>
  <groupId>org.restlet.jee</groupId>
  <artifactId>org.restlet.ext.json</artifactId>
</dependency>
<dependency>
  <groupId>org.restlet.jee</groupId>
  <artifactId>org.restlet.ext.httpclient</artifactId>
</dependency>
<dependency>
  <groupId>org.restlet.jee</groupId>
  <artifactId>org.restlet.ext.xstream</artifactId>
  <version>2.0.1</version>
</dependency>
<dependency>
  <groupId>org.restlet.jee</groupId>
  <artifactId>org.restlet.ext.xml</artifactId>
</dependency>
...

“JAX-RS: The Java API for RESTful Web Services” Talk at Devoxx08

December 15th, 2008 by nils

This talk was given by Paul Sandoz. He showed a few examples and listed the following existing implementations of JSR 311 (JAX-RS):

He was testing the services on a command line with curl (i.e. curl -v -d x=1 -H “Accept: application/xml” http://localhost:8080/xyz or “Accept: application/json”).

The JAX-RS Overview is supposed to be a good starting point to implement RESTful web services. His presentation and a zip file wih examples can be downloaded from his blog.