This sample demonstrates the Http REST capabilities in Citrus where Citrus calls REST API on a todo web application. REST features are also described in detail in reference guide

Objectives

The todo-list sample application provides a REST API for managing todo entries. Citrus is able to call the API methods as a client in order to validate the Http response messages.

We need a Http client component in the configuration:

@Bean
public HttpClient todoClient() {
    return CitrusEndpoints.http()
                        .client()
                        .requestUrl("http://localhost:8080")
                        .build();
}

In test cases we can reference this client component in order to send REST calls to the server.

http()
    .client(todoClient)
    .send()
    .post("/todolist")
    .contentType("application/x-www-form-urlencoded")
    .payload("title=${todoName}&description=${todoDescription}");

As you can see we are able to send x-www-form-urlencoded message content as POST request. The response is then validated as Http 200 OK.

http()
    .client(todoClient)
    .receive()
    .response(HttpStatus.OK);

Run

You can run the sample on your localhost in order to see Citrus in action. Read the instructions how to run the sample.