Daily Archives: 2012-01-08

Simple Webservice Echo Test

While troubleshooting some PHP Curl issues, I found and used http://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.

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).

Plain text example

$ curl http://scooterlabs.com/echo
[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] =>
[time_utc] => 2012-01-08T21:33:28+0000
[info] => Echo service from Scooterlabs (http://www.scooterlabs.com)

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" : "",
"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"?>
<User-Agent>curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3
<info>Echo service from Scooterlabs (http://www.scooterlabs.com)


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.