Getting Started Guide

Welcome to this getting started guide. In this guide you will learn how to use the Chaotics API to create your first endpoint.

Lets get started!

Contents

Simple successful response

We'll use the create API passing a simple request body to describe a simple successful response.

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "apiResponses": [ { "responseStatusCode":200, "responseContentType":"text/plain", "charset":"UTF-8", "responseBody":"ok" } ] }' \
    https://api.chaotics.io/endpoint/create
ChaoticsClient chaoticsClient = new ChaoticsClient();
ApiSecretPair apiSecretPair = chaoticsClient.createEndpoint(CreateApiRequest.builder() 
        .withApiResponses(Collections.singletonList(ApiResponse.builder() 
                .withResponseStatusCode(200) 
                .withResponseContentType("text/plain") 
                .withCharset("UTF-8")
                .withResponseBody("ok")
                .build()))
        .build());

Here we're create a very simplistic endpoint which only response succesfully with status code of 200 and the body of "ok". We're tell Chaotics that the character set is UTF-8 and that we'd like it to response with a content type header of "text/plain".

Failure response

Using the same functionality we can create an endpoint which will behave as if it is failing.

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "apiResponses": [ { "responseStatusCode":500, "responseContentType":"text/plain", "charset":"UTF-8", "responseBody":"internal error" } ] }' \
    https://api.chaotics.io/endpoint
ChaoticsClient chaoticsClient = new ChaoticsClient();
ApiSecretPair apiSecretPair = chaoticsClient.createEndpoint(CreateApiRequest.builder() 
        .withApiResponses(Collections.singletonList(ApiResponse.builder() 
                .withResponseStatusCode(500) 
                .withResponseContentType("text/plain") 
                .withCharset("UTF-8")
                .withResponseBody("internal error")
                .build()))
        .build());

In this example we've created an endpoint which will response with a 500 status code and with a body of
Internal Error.

Introducing additional latency

There might be times when you want to test not what happens on a failure, but what happens when an API responses slowly. With Chaotics you can configure your endpoint to delay its response.

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "apiResponses": [ { "latency":5000, "responseStatusCode":200, "responseContentType":"text/plain", "charset":"UTF-8", "responseBody":"ok" } ] }' \
    https://api.chaotics.io/endpoint
ChaoticsClient chaoticsClient = new ChaoticsClient();
ApiSecretPair apiSecretPair = chaoticsClient.createEndpoint(CreateApiRequest.builder() 
        .withApiResponses(Collections.singletonList(ApiResponse.builder() 
                .withLatency(5000)
                .withResponseStatusCode(200) 
                .withResponseContentType("text/plain") 
                .withCharset("UTF-8")
                .withResponseBody("ok")
                .build()))
        .build());

Here we're using the latency attribute on the ApiResponse object to introduce an amount of additional latency to add to each response.

Note. This doesn't guarantee that the response from Chaotics will be exactly the specified amount. It means that this amount of additional latency will be added to the response.

Randomised responses

Chaotics supports endpoints which can respond randomly with one of a predefined list of responses. This functionality can be useful in as part of a larger test where you want unpredictable behavior.

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "apiResponses": [ { "responseBody":"response 1", "responseStatusCode":200, "responseContentType":"text/plain", "charset":"UTF-8" }, { "responseBody":"response 2", "responseStatusCode":200, "responseContentType":"text/plain", "charset":"UTF-8" } ] }' \
    https://api.chaotics.io/endpoint
ChaoticsClient chaoticsClient = new ChaoticsClient();
ApiSecretPair apiSecretPair = chaoticsClient.createEndpoint(CreateApiRequest.builder()
        .withApiResponses(Arrays.asList(
                ApiResponse.builder()
                        .withResponseStatusCode(200)
                        .withResponseContentType("plain/text")
                        .withCharset("UTF-8")
                        .withResponseBody("response 1")
                        .build(),
                ApiResponse.builder()
                        .withResponseStatusCode(200)
                        .withResponseContentType("plain/text")
                        .withCharset("UTF-8")
                        .withResponseBody("response 2")
                        .build()
        ))
        .build());

In this example there are two different possible responses. On average Chaotics will response with each evenly. You can configure more than two responses, again each will have an even probability of being used.

Weighted randomised responses

Taking the randomised responses further you can apply a weighting to each response. This could be used to demonstrate a partial failure of a system. Where one response is the expected successful response and on occasion a failure response is returned instead.

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "apiResponses": [ { "responseBody":"ok", "responseStatusCode":200, "responseContentType":"text/plain", "charset":"UTF-8", "weight": 9 }, { "responseBody":"error", "responseStatusCode":500, "responseContentType":"text/plain", "charset":"UTF-8", "weight":1 } ] }' \
    https://api.chaotics.io/endpoint
ChaoticsClient chaoticsClient = new ChaoticsClient();
ApiSecretPair apiSecretPair = chaoticsClient.createEndpoint(CreateApiRequest.builder()
        .withApiResponses(Arrays.asList(
                ApiResponse.builder()
                        .withResponseStatusCode(200)
                        .withResponseContentType("plain/text")
                        .withCharset("UTF-8")
                        .withResponseBody("ok")
                        .withWeight(9)
                        .build(),
                ApiResponse.builder()
                        .withResponseStatusCode(500)
                        .withResponseContentType("plain/text")
                        .withCharset("UTF-8")
                        .withResponseBody("error")
                        .withWeight(1)
                        .build()
        ))
        .build());

Here I'm configuring a successful response with a weighting of 9 and an error with the weighting of 1. This means that on average 90% of the responses will be with the successful response and 10% of them will be with the error response.