2

i would like to access the body of a GET request from a REST server resource (with restlet 2.0). This for a few reasons:

  • i would like to send parameters (in a JSON format) in the GET request, lets say for example "return the full object that has these fields/values ... "

  • i would like to protect the parameters of the URL request using https, and if i specify them as url parameters i cant protect them.

  • i would like to avoid very long urls.

i was also reading: HTTP GET with request body

i was looking in the code/examples and the api but i didn't find a solution, could you suggest me an approach? do you see a better framework/solution? thanks !!! kocisky

Community
  • 1
  • 1
kky
  • 141
  • 2
  • 13

2 Answers2

0

Why not use POST? You already threw away the ability to cache responses by including the criteria in the body. So what benefit is there to using GET?

Using POST has to be less of a subversion of the HTTP spec than sending a GET body.

Darrel Miller
  • 129,370
  • 30
  • 183
  • 235
0

In order to do what you want, you need to use the Request and Client API of Restlet. This can't be done using the ClientResource class. You can find below some hints to implement that:

String endpoint = "http://localhost:8084/accounts/accountId/mails/mailId";
Request request = new Request(Method.GET, endpoint);
StringRepresentation representation = new StringRepresentation(
                                  "param1=value1&param2=value2");
request.setEntity(representation);

Context context = new Context();
context.getParameters().add("tracing", "true");
Client client = new Client(context, Protocol.HTTP);
Response response = client.handle(request);

The tracing parameter allows you seeing what is actually sent when using the internal Restlet connector.

Hope it'll help you, Thierry

Thierry Templier
  • 182,931
  • 35
  • 372
  • 339