Today: April 21, 2021 3:22 pm
A collection of Software and Cloud patterns with a focus on the Enterprise

Echo for REST client debugging

Recently I was debugging a REST client class in Java. The service I was calling simply returned that the request was incomplete. Without access to the service logs and without more meaningful feedback from the service, I decided to create an echo script that would allow me to see exactly what my REST client was sending.

For simplicity I used a LAMP installation on Ubuntu running inside virtual box on my Windows 7 development machine. I could have installed something like WAMPServer, but I prefer to leave my machine as clean as possible. Virtual Box is an ideal choice for this since I can create any type of host with any configuration and leave my own development machine unaffected.

I wrote my echo script in PHP. Here’s the code:

$raw_post = file_get_contents("php://input");
echo $raw_post;

The script is pretty simple. I just echos back to me what it sees. This includes the headers and the data contained in the BODY of the request. Note that the body will be empty for GET and DELETE (or should be anyway).

Here’s what a call to my service looks like:

As you can see, I can now see exactly what my REST client is sending to any service. This enables me to debug the client until I know that what I’m sending just right.

Note that if it becomes necessary to contact the owner of the REST service, I now have additional details to provide him and help him identify potential problems with his service. This is much better than claiming his service doesn’t work right and later finding that I actually wasn’t sending the request properly.


Java code to send a POST to a REST client:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.