Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Latest commit

 

History

History
86 lines (76 loc) · 2.47 KB

run-api-methods.md

File metadata and controls

86 lines (76 loc) · 2.47 KB

Run API methods

See below for descriptions and examples of the available API methods in this application. The following substitutions are required in these examples:

  • MY_API_KEY should bu substituted for the API key defined in the API gateway usage plan and aligns with the API_KEY in the .env file.
  • MY_DOMAIN.NET should be substituted for the API_DOMAIN_NAME value defined in the .env file.

Method: GET /servers

> # return all Minecraft game servers in your server farm
> curl -s -H 'x-api-key:MY_API_KEY' -X GET 'https://MY_DOMAIN.NET/servers' | jq .
{
  "servers": [
    {
      "name": "myworld",
      "fullName": "minecraft-main-server-myworld",
      "environment": "main",
      "instanceId": "i-0123abcd4567efghi",
      "state": "running",
      "publicIpAddress": "10.32.54.76"
    },
    {
      "name": "otherworld",
      "fullName": "minecraft-main-server-otherworld",
      "environment": "main",
      "instanceId": "i-abcd1234efgh56789",
      "state": "stopped",
      "publicIpAddress": "10.32.54.78"
    }
}

Method: GET /servers/myworld

> # return info about a Minecraft game server in your farm by name
> curl -s -H 'x-api-key:MY_API_KEY' -X GET 'https://MY_DOMAIN.NET/servers/myworld' | jq .
{
  "name": "myworld",
  "fullName": "minecraft-main-server-myworld",
  "environment": "main",
  "instanceId": "i-0123abcd4567efghi",
  "state": "running",
  "publicIpAddress": "10.32.54.76"
}

Method: POST /servers/myworld

> # change state of a Minecraft game server to "stopped"
> curl -s -H 'x-api-key:MY_API_KEY' -X POST -d '{"state": "stopped"}' 'https://MY_DOMAIN.NET/servers/myworld' | jq .
{
  "name": "myworld",
  "fullName": "minecraft-main-server-myworld",
  "environment": "main",
  "instanceId": "i-0123abcd4567efghi",
  "state": "stopped",
  "publicIpAddress": "10.32.54.76"
}
> # change state of a Minecraft game server to "running"
> curl -s -H 'x-api-key:MY_API_KEY' -X POST -d '{"state": "running"}' 'https://MY_DOMAIN.NET/servers/myworld' | jq .
{
  "name": "myworld",
  "fullName": "minecraft-main-server-myworld",
  "environment": "main",
  "instanceId": "i-0123abcd4567efghi",
  "state": "running",
  "publicIpAddress": "10.32.54.76"
}

Method: GET /servers/myworld/users

> # return users on a Minecraft game server in your farm by name
> curl -s -X GET -H 'x-api-key:MY_API_KEY' 'https://MY_DOMAIN.NET/servers/myworld/users' | jq .
{
  "count": 2,
  "names": [
    "user1",
    "anotheruser"
  ]
}