HTTP/WebSocket Sample Service

The HTTP sample service provided by Testable exposes the API defined below. Feel free to use it when first trying out Testable to better understand how the platform works.

The service is accessible at http://sample.testable.io.

HTTP Resources

Basic Service Info

GET /

Response

{
    name: "sample-http",
    startedAt: "2015-05-07T05:51:09.705Z"
}

Last Quote for a Symbol

GET /stocks/:stock

Response

{
    symbol: "IBM",
    price: 40.91862487858329,
    exchange: "NASDAQ"
}

Breaking Point Simulator

Useful endpoint for simulating a service degrading when it has more than a certain number of concurrent users.

GET /breaking-point/:testName

Parameters

  • testName: A string that groups requests. All overlapping requests with the same test name are counted as concurrent users.
  • max: How many concurrent users before the response time degrades from regularLatencyMs to brokenLatencyMs. Defaults to 25.
  • regularLatencyMs: Response time in milliseconds when there are less than or equal to max concurrent users. Defaults to 1000ms.
  • brokenLatencyMs: Response time in milliseconds when there are more than max concurrent users. Defaults to 5000ms.

Response

{
    symbol: "IBM",
    price: 40.91862487858329,
    exchange: "NASDAQ"
}

Login

POST/login

Login resource where the following credentials are the only ones that will work:

{
    user: "admin",
    password: "admin"
}

Response

  • Status Code = 201 (CREATED): Valid credentials
  • Status Code = 403 (UNAUTHORIZED): Invalid user or password
  • Status Code = 404 (BAD_REQUEST): Invalid request structure

WebSocket Endpoint

The sample service exposes a SockJS service to stream stock quotes at:

/streaming

One can either use a SockJS client library or simply open a raw websocket to /streaming/websocket. The frames received at this endpoint will be binary frames. See below for a sample Javascript client that runs in modern browsers.

Subscribe

{
    subscribe: ":symbol"
}

Unsubscribe

{
    unsubscribe: ":symbol"
}

Stock Quote

{
    "symbol":"IBM",
    "price":78.57185908275451,
    "exchange":"NYSE"
}

Sample WebSocket Javascript Client

<script>
    var sock = new WebSocket('ws://sample.testable.io/streaming/websocket');
    sock.onopen = function() {
        sock.send(JSON.stringify({ subscribe: "IBM" }))
    };
    sock.onmessage = function(e) {
        var reader = new FileReader();
        reader.onload = function(event){
          console.log('On Message: ' + JSON.stringify(reader.result));
        };
        reader.readAsText(e.data);
    };
    sock.onclose = function() {
        console.log('close');
    };
</script>

Sample SockJS Javascript Client

<script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
<script>
    var sock = new SockJS('ws://sample.testable.io/streaming');
    sock.onopen = function() {
        sock.send(JSON.stringify({ subscribe: "IBM" }))
    };
    sock.onmessage = function(e) {
        console.log('On Message: ' + JSON.stringify(e.data));
    };
    sock.onclose = function() {
        console.log('close');
    };
</script>

Socket.io Server

A Socket.io echo service is provided at http://sample.testable.io:5811

Sample Socket.io Javascript Client

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.8/socket.io.js"></script>
<script>
    var socket = io('http://sample.testable.io:5811');
    socket.on('connect', function(){
        console.log('connected');
        socket.emit('event', 'Echo test');
    });
    socket.on('event', function(data){
        console.log(data);
        socket.close();
    });
    socket.on('disconnect', function(){
        console.log('disconnected');
    });
</script>

Engine.io Server

A Engine.io echo service is provided at http://sample.testable.io:5812. Engine.io is the implementation of transport-based cross-browser/cross-device bi-directional communication layer for Socket.IO.

Sample Engine.io Javascript Client

<script src="https://cdnjs.cloudflare.com/ajax/libs/engine.io-client/1.6.11/engine.io.js"></script>
<script>
    var socket = eio('http://sample.testable.io:5812');
    socket.on('open', function(){
        console.log('opened: ' + socket.id);
        socket.send('Echo test');
        socket.on('message', function(data){
            console.log(data);
            console.close();
        });
        socket.on('close', function(){
            console.log('closed: ' + socket.id);
        });
    });
</script>