Simple Webservice Echo Test

While troubleshooting some PHP Curl issues, I found and used respondto.it (and later http://requestb.in/) which allows you to create a dummy webservice endpoint which reveals the full request made to it by your code. (Note: both of those services are offline now, see my newer article linked below for a more recent list.)

An even simpler use case would be a webservice that simply returned data about the request directly to the calling application. I just created such a simple echo webservice on my scooterlabs.com domain.

Update 2012-03-23: Added XML response example as well (scooterlabs.com/echo.xml).

Update 2019-04-30: Updated to reflect services which have gone offline. I’ve also written up a quick recent survey of HTTP inspector services which are still available.

Plain Text Example

$ curl http://scooterlabs.com/echo
Array
(
    [method] => GET
    [headers] => Array
        (
            [User-Agent] => curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3
            [Host] => scooterlabs.com
            [Accept] => */*
        )

    [request] => Array
        (
            [foo] => bar
        )

    [client_ip] => 68.125.160.82
    [time_utc] => 2012-01-08T21:33:28+0000
    [info] => Echo service from Scooterlabs (http://www.scooterlabs.com)
)

Plain text response with public IP address:

$ curl http://scooterlabs.com/echo?ip
10.11.12.13

JSON Example

$ curl --silent curl http://scooterlabs.com/echo.json?foo=bar | json_xs
{
   "info" : "Echo service from Scooterlabs (http://www.scooterlabs.com)",
   "request" : {
      "foo" : "bar"
   },
   "headers" : {
      "User-Agent" : "curl/7.21.3 (i386-portbld-freebsd7.3) libcurl/7.21.3 OpenSSL/1.0.0e zlib/1.2.3 libidn/1.22",
      "Accept" : "*/*",
      "Host" : "scooterlabs.com"
   },
   "client_ip" : "66.39.158.129",
   "time_utc" : "2012-01-08T22:07:54+0000",
   "method" : "GET"
}

XML Example

$ curl --silent http://scooterlabs.com/echo.xml?foo=bar | xml_pp

<?xml version="1.0"?>
<echo>
  <method>GET</method>
  <headers>
    <User-Agent>curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3</User-Agent>
    <Host>scooterlabs.com</Host>
    <Accept>*/*</Accept>
  </headers>
  <request>
    <foo>bar</foo>
  </request>
  <client_ip>68.122.10.221</client_ip>
  <time_utc>2012-03-24T17:05:49+0000</time_utc>
  <info>Echo service from Scooterlabs (http://www.scooterlabs.com)</info>
</echo>

Source

Source code is up on Github: https://github.com/bcantoni/echotest. If anyone has any comments or feedback, let me know here or on Github.