When you develop and test your integration with our MB2 API, you can use our MB2 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-mb2-simulator
The simulator needs to be provided with data in JSON 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:
You can download sample JSON 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.
We have provided the data which is almost the same as real messages. This data can be replayed automatically by enabling the replay service while running the docker image. More information can be found at the bottom of this page.
We will start the Docker container and tell it to accept requests on port 3000. Then we make a few requests using curl to get to know how the simulator and the API works.
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 3000:3000 troperty/customerapi-mb2-simulator
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 http://localhost:3000/customerapi/authenticate/subscript/ \
-H 'Content-Type: application/json' \
-d '{"key":"mykey","secret":"mysecret"}' \
-v
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:3000/customerapi/events \
-H 'Authorization: Bearer dGVzdHVzZXI='
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 http://localhost:3000/api/message \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '<JSON_FILE_CONTENT>'
You can download sample JSON files from this GitHub repository and use those for your development and testing.
curl http://localhost:3000/api/message \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '@./samples/2024-05-02_1714619368_24_RaceDayTrot.json'
See example code on: https://github.com/Troperty/racedata-node-samples
This will deliver the file as a WebSocket message.
curl http://localhost:3000/api/message \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '@./samples/2024-05-01_1714564081_5_3_Last500MetersTrot.json'
You can run the same docker image with an optional environment variable to have it automatically create the events that are made available for download.
docker run -p 3000:3000 -e "AUTO_REPLAY_MESSAGE_INTERVAL=5000" troperty/customerapi-mb2-simulator
Here, you can change the value 5000 milliseconds to any number of milliseconds based on your needs. It will generate one message after every interval.
Also, you can pass an optional environment variable INITIAL_DELAY along with AUTO_REPLAY_MESSAGE_INTERVAL.
docker run -p 3000:3000 -e "AUTO_REPLAY_MESSAGE_INTERVAL=5000" -e "INITIAL_DELAY=30000" troperty/customerapi-mb2-simulator
If INITIAL_DELAY is not passed, it will default to whatever value of AUTO_REPLAY_MESSAGE_INTERVAL is set. But, if you want some more time to connect your web-socket to the server after start-up, or for whatever other reason, you can get more time by setting INITIAL_DELAY to a bit higher value than AUTO_REPLAY_MESSAGE_INTERVAL.
All the APIs of the simulator will continue to function as is.