The Friday Fragment

Published on 15 October 2010
This post thumbnail

It's Friday, and time again for the Friday Fragment: our weekly programming-related puzzle.

This Week's Fragment

We'll continue this week along our simple web service vein with the flip-side: calling a web service.

Write code to call your rock, paper, scissors web service and keep counts of how many times each is returned.

To “play along”, provide either the URL or the code for the solution. You can post it as a comment or send it via email. If you didn't implement your own web service from last week or want to call mine instead, use this URL:

Last Week's Fragment - Solution

Last week's puzzle was to code a simple REST web service that, when called via GET, randomly answers rock, paper, or scissors. Your result could be fancy (wrapped in XML or JSON syntax), or simple: just the word.

Here's one really simple solution, in PHP:

Yes, to quote Billy Mays, "it's just that easy!"

Now you may be thinking it's not a real web service if it doesn't use some combination of JAX-WS, Axis, Axis2, Castor, JiBX, JAXB, over-hopped servlets, lots of generated value/transfer objects and/or some other similar Rube Goldberg bloatware solution. But then that wouldn't be a fragment. REST without XML is easy enough, and we want to keep this really simple, demonstrating logic, not plumbing. If you're an IIS fan (or don't want to use PHP or Java), give C# a spin, where even SOAP/XML web services are easy.

And perhaps you see where all this is going... the "bot wars" are coming soon!