I recommend RestFixture. Despite the name it is a very simple HTTP client - you can craft any HTTP request then check the response that comes back: The status code, the headers (using regular expressions to check just the headers you're interested in) and the body (using XPath or JavaScript expectations to check just the nodes you're interested in). Handles either XML or JSON based on the value of the Content-Type header. Handles almost all the HTTP verbs: GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE. Don't think it handles PATCH though.
I've just started playing with Fried Hoeben's HttpTest fixtures, XmlHttpTest and JsonHttpTest (see Fried's answer elsewhere in this thread). They appear to have slightly more features than RestFixture. For example, they support templates which allow you to send repeated requests that are identical apart from certain values embedded in the body. You specify the template once then just list the values to pass into it for each call, avoiding having to repeatedly specify the whole request body each time.
On the other hand, for simple calls to web services I think RestFixture is easier to use.
RestFixture Overview
RestFixture is easy to remember as it effectively has only three types of commands:
1) set: setHeader and setBody. For specifying headers or the body of an HTTP request;
2) let: For assigning a value to a variable;
3) HTTP Verbs: Sends an HTTP request.
This is why I like RestFixture - the syntax for all HTTP verbs are the same:
| verb | uri | ?responseStatusCode | ?responseHeaders | ?responseBody |
You specify the HTTP verb, the URI to send the request to, the response status code you expect, the response headers you want to check (leave out any headers you don't want to test; regular expressions can be used) and the nodes in the response body to check.
Using the same syntax for every HTTP verb, I think, makes for very clean tests.
Example
| Import |
| smartrics.rest.fitnesse.fixture |
|Table: Rest Fixture | http://localhost:9876 |
| setBody | <resource><name>a name</name><data>data</data></resource> |
| POST | /resources/ | 201 | | no-body |
| let | id | header | Location:/resources/(.+) | |
| Table: Rest Fixture | http://localhost:9876 |
| GET | /resources/%id% | 200 | Content-Type : application/xml | !- /resource/name[text()='a name']
/resource/data[text()='data'] -! |
This test generates a new item via a POST, reads the new item's ID back and assigns it to a variable, then uses that ID value with a GET to verify the new item exists and contains the right data.
The POST request expects the response to have a 201 status code and no body. The GET request expects the response to have a 200 status code and a Content-Type header set to application/xml. It expects the body to have a name node set to "a name" and a data node set to "data".
This example is for a RESTful web service but RestFixture would work just as well for SOAP. The body you specify for the POST would just be bigger.
Installation and Use
RestFixture can be found at http://github.com/smartrics/RestFixture. It includes links to documentation with extensive examples.
Here are instructions for building and installing RestFixture using Maven: workflow of creating tests using RestFixture
Coming from a .NET background without any experience of Maven, however, I found the easiest way to install it was to add it to an existing FitNesse installation:
1) Download the zipped binary from Maven Central, at http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22smartrics-RestFixture%22
2) Unpack the zip file to a directory alongside the FitrNesseRoot directory (the directory should NOT be under FitNesseRoot). For the sake of example let's call the directory RestFixtureLib (in reality you can name the directory anything you like);
3) In the RestFixtureLib directory delete the FitNesse-{version}.jar file, as we already have FitNesse installed;
4) In the test page that will include RestFixture tests add the RestFixtureLib directory to the class path:
!path RestFixtureLib/*.jar
(or whatever the path is to the directory you unpacked RestFixture to)
This class path definition could be included in a suite page or the root page if you'll be using RestFixture on more than one page.
5) RestFixture can be used with either the FIT or the SLIM test systems. If using SLIM include the following definition in the test page:
!define TEST_SYSTEM {slim}
6) It makes tests a lot less long-winded if you import the RestFixture namespace at the top of your test page:
| Import |
| smartrics.rest.fitnesse.fixture |
Then you can just define a test with
|Table: Rest Fixture | ... |
| ... |