Introduction to the API

This tutorial uses a simple API implementing the Mars Rover Kata in go. As we don’t want to put too much effort into the API and focus on the API gateway, we use it as a Docker container.

Start the server

To start the server we create a file called docker-compose.yaml in an empty directory (this will then be the root directory of this tutorial). Please add the following as the files content:

version: '3'

services:
  rover-api:
    container_name: rover-api
    image: registry.gitlab.com/ngstmnn/go-rover:0.1.1-debug
    ports:
      - 80:8080 # we expose the servers port 8080 at our localhost:80

Now we only need to start our environment with the following command:

docker-compose up -d

Call the API

The API has 5 Endpoints

  • GET /rovers - lists the ids of all existing rovers

    curl -X GET \
      http://localhost/rovers
  • POST /rovers - creates a new rover and returns its data

    curl -X POST \
      http://localhost/rovers
  • GET /rovers/{ID} - returns the data of the rover identified by {ID}

    curl -X GET \
      http://localhost/rovers/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  • PUT /rovers/{ID}/command - sends a list of commands to the rover to make it move

    curl -X PUT \
      http://localhost/rovers/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/command \
      -H 'Content-Type: application/json' \
      -d '{"commands":["r","f","l","f","f","l"]}'
  • DELETE /rovers/{ID} - deletes the rover identified by {ID}

    curl -X DELETE \
      http://localhost/rovers/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Please replace xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx with a valid UUID that was returned from the API.

Stop the server

Once you played around with the API a little you can stop the server by running the following command:

docker-compose down