Resources

Using the API Simulator

When you develop and test your integration with our API, you can use our API simulator that is available on Docker Hub. You can run the simulator locally inside your own network, or we can set it up for you in our cloud environment and give you a public endpoint that you can access. The simulator is compatible with the production API.

You will find in-depth instructions on using the simulator on the link to Docker Hub below. Here we will focus on how to get started.

https://hub.docker.com/r/troperty/customerapi-broker-simulator


Data options

The simulator needs to be provided with data in XML format, in order for you to consume the data through the API. The data should follow the same format as described in the channels list. There are two options for getting data into the simulator:

  1. You can download sample XML files here. Send those files to the simulator (described below) to be able to consume the data through the API in the same way you would from the production endpoint.

  2. We can provide you with data which has been recorded from actual live races, and then had all personal information anonymised. This data can be replayed automatically by using a replay service together with the simulator. Both simulator and replay service are found on Docker Hub, and can be installed and started very easily using a Docker Compose file. More information can be found at the bottom of this page.


Getting started

We will start the Docker container and tell it to accept requests on port 8080. Then we make a few requests using curl to get to know how the simulator and the API works.


Starting the simulator

You need to have Docker installed on your local machine. The API simulator will automatically be pulled from Docker Hub when you run the command below if it’s not already on your machine.

$ docker run -p 8080:8080 troperty/customerapi-broker-simulator


Making the authentication request

Make note of the Authentication header that you get in the response. This contains the token that you will use to call the other API:s.

When you use the simulator this token will never change, but it’s still a good idea to use it as if you were already working with the production API.

$ curl -X POST http://localhost:8080/customerapi/authenticate/subscript/ \
    -u testuser:testpass \
    -H 'Content-Type: application/json' \
    -d '{"key":"mykey","secret":"mysecret"}' \
    -v


Listen to the durable channel

Here we need to supply the token that we got from the previous authentication request. If there’s no message waiting for us, the request will wait for 60 seconds before it returns an empty response.

$ curl http://localhost:8080/customerapi/channels/listen \
    -H 'Authorization: Bearer dGVzdHVzZXI='


Post a message to the durable channel

This endpoint is unique to the simulator, and does not require authentication. This is how you can send test data to yourself. In production, this will be handled by Swedish Trotting Association.

$ curl -X POST http://localhost:8080/customerapi/channel/id/Durable?payloadKey=hello \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -d '<xml>Hello world!</xml>'


Post an XML file to the durable channel

You can download sample XML files from this GitHub repository and use those for your development and testing.

curl -X POST http://localhost:8080/customerapi/channel/id/Durable?payloadKey=race \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -d '@./samples/RacingCardRace.xml'


Listen on WebSocket for transient messages

See example code on: https://github.com/Troperty/racedata-node-samples


Post an XML file to the transient channel

This will deliver the file as a WebSocket message.

curl -X POST http://localhost:8080/customerapi/channel/id/NonDurable?payloadKey=race \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -d '@./samples/TimeToStartTrot.xml'


Replay recorded race events

Contact Swedish Trotting Association to receive a Docker Compose file, and a collection of messages that have been recorded from actual live messages. You can use the Docker Compose file to replay the recorded messages using the simulator. The messages will be replayed with the same timing as they were recorded, or you can set a parameter to control the maximum delay between messages.

We can also help you set up a simulator with replay on an endpoint in our cloud environment.


Set maximum delay between messages
# Mac/Linux
export REPLAY_MAX_DELAY=5000

# Windows
set REPLAY_MAX_DELAY=5000


Start replay

docker-compose up


docker-compose.yaml
version: '3'
services:
  broker:
    image: 'troperty/customerapi-broker-simulator'
    ports:
      - '8080:8080'
  player:
    image: 'troperty/broker-replay:3'
    environment: 
      - MAX_DELAY=${REPLAY_MAX_DELAY}
    volumes:
      - ./recording/:/app/recording