-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update API Reference to match new sidebar.
- Loading branch information
Showing
19 changed files
with
206 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: Introduction | ||
--- | ||
|
||
# Introduction | ||
|
||
Battlesnake is played by responding to simple webhooks sent to your server by the game engine. Developers build a web server that receives and responds to HTTP requests, and how your server responds to these requests controls how your Battlesnake behaves. | ||
|
||
|
||
## Requests | ||
|
||
All requests made from the game engine to your Battlesnake server will have the following properties. | ||
|
||
### Content-Type | ||
|
||
Requests will contain [JSON-encoded](https://www.json.org/) request bodies. Your server is responsible for receiving and parsing this data correctly (although most modern web frameworks come with easy ways to handle this type of request). | ||
|
||
|
||
## Responses | ||
|
||
All responses from your Battlesnake server must abide by these rules when responding to game engine requests. If your server fails to send a valid response in any way, the game engine will consider it an error and act accordingly. | ||
|
||
### Content-Type | ||
|
||
Valid responses must be JSON-encoded strings with the Content-Type header set to \`_application/json\`_. | ||
|
||
### Status Codes | ||
|
||
Valid responses must return an _HTTP 200 OK_ status code. If any other status code is returned, the game engine will consider it an invalid response. | ||
|
||
### Latency & Timeouts | ||
|
||
Your Battlesnake server must respond to requests made by the game engine within the given timeout value. This value is provided in the request body as a [property on the game object](api/objects/game). | ||
|
||
In most games this will be 500ms, however, this value can technically vary from game to game. If your response does not reach the game engine within the specified timeout, the game engine will consider it an invalid response. | ||
|
||
:::tip | ||
Note that these time limits must include round-trip latency between the game engine and your server - be sure to take that into consideration when deciding how long to spend computing your response. | ||
::: | ||
|
||
|
||
## Response Error Handling | ||
|
||
Any invalid responses will be treated as errors by the game engine, and your Battlesnake's next move will be chosen for you - even if that means certain elimination. | ||
|
||
**An error on the first move of a game** will move your Battlesnake `up` by default. This value is hardcoded into the game engine with no particular meaning behind it. | ||
|
||
**Errors on subsequent turns** will repeat your previous move. For example, if your Battlesnake successfully moves `right` on turn N, a timeout on turn N+1 will result in your Battlesnake moving `right` again. This applies even if the game engine chose your move for you on the previous turn due to an error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
title: Webhooks | ||
--- | ||
|
||
# Webhooks | ||
|
||
This page documents the technical details of the webhooks sent from the game engine to your Battlesnake server. They all originate from the Battlesnake Server URL that you provide when creating your Battlesnake in the dashboard. | ||
|
||
|
||
## Battlesnake Details | ||
|
||
HTTP Request: `GET /` | ||
|
||
An empty GET request made to the root URL of your Battlesnake, used to load customization, check latency, and verifying successful communications between the game engine and your Battlesnake. | ||
|
||
#### Request Data | ||
|
||
None, the game engine will send an empty request body. | ||
|
||
#### Response Properties | ||
|
||
| **Property** | **Type** | **Description** | | ||
| -------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| **apiversion** | string _(required)_ | Version of the Battlesnake API implemented by this Battlesnake. Currently only API version 1 is valid. <em>Example: "1"</em> | | ||
| **author** | string _(optional)_ | Username of the author of this Battlesnake. If provided, this will be used to verify ownership. <em>Example: "BattlesnakeOfficial"</em> | | ||
| **color** | string _(optional)_ | Hex color code used to display this Battlesnake. Must start with "#", followed by 6 hexadecimal characters. <em>Example: "#888888"</em> | | ||
| **head** | string _(optional)_ | Head customization. <em>Example: "default"</em> | | ||
| **tail** | string _(optional)_ | Tail customization. <em>Example: "default"</em> | | ||
| **version** | string _(optional)_ | An optional version string for your Battlesnake. This value is not used in gameplay, but can be useful for tracking deployments on your end. | | ||
|
||
See [Customization Guide](/guides/customizations) for more info about changing your Battlesnake's color, head, and tail. | ||
|
||
#### Example Response | ||
|
||
```json title="200 OK" | ||
{ | ||
"apiversion": "1", | ||
"author": "MyUsername", | ||
"color": "#888888", | ||
"head": "default", | ||
"tail": "default", | ||
"version": "0.0.1-beta" | ||
} | ||
``` | ||
|
||
## Game Started | ||
|
||
HTTP Request: `POST /start` | ||
|
||
Your Battlesnake will receive this request when it has been entered into a new game that is about to begin. Every game has a unique ID that can be used to allocated resources or data you may need. Your response to this request will be ignored. | ||
|
||
#### Request Data | ||
|
||
| **Parameter** | **Type** | **Description** | | ||
| ---------------------------------- | -------- | ----------------------------------------------------------------------------- | | ||
| **game** | object | [Game Object](objects/game) describing the game being played. | | ||
| **turn** | integer | Turn number (always 0 for new games). | | ||
| **board** | object | [Board Object](objects/board) describing the initial state of the game board. | | ||
| **you** | object | [Battlesnake Object](objects/battlesnake) describing your Battlesnake. | | ||
|
||
#### Response Properties | ||
|
||
Responses to this request are ignored by the game engine. | ||
|
||
|
||
## Move | ||
|
||
HTP Request: `POST /move` | ||
|
||
This request will be sent for every turn of every game that your Battlesnake plays. Use the information provided to determine how your Battlesnake will move on that turn, either up, down, left, or right. | ||
|
||
#### Request Parameters | ||
|
||
| **Parameter** | **Type** | **Description** | | ||
| ---------------------------------- | -------- | ----------------------------------------------------------------------------- | | ||
| **game** | object | [Game Object](objects/game) describing the game being played. | | ||
| **turn** | integer | Turn number for this move. | | ||
| **board** | object | [Board Object](objects/board) describing the initial state of the game board. | | ||
| **you** | object | [Battlesnake Object](objects/battlesnake) describing your Battlesnake. | | ||
|
||
|
||
#### Response Properties | ||
|
||
| **Property** | **Type** | **Description** | | ||
| ------------- | ------------------- | ---------------------------------------------------------------------------------------------------- | | ||
| **move** | string | Your Battlesnake's move for this turn. Valid moves are "up", "down", "left", or "right". | | ||
| **shout** | string _(optional)_ | An optional message sent to all other Battlesnakes on the next turn. Must be 256 characters or less. | | ||
|
||
|
||
#### Example Response | ||
|
||
```json title="200 OK" | ||
{ | ||
"move": "up", | ||
"shout": "Moving up!" | ||
} | ||
``` | ||
|
||
## Game Over | ||
|
||
HTTP Request: `POST /end`` | ||
|
||
Your Battlesnake will receive this request whenever a game it was playing has ended. Use it to learn how your Battlesnake won or lost and deallocate any server-side resources. Your response to this request will be ignored. | ||
|
||
#### Request Data | ||
|
||
| **Parameter** | **Type** | **Description** | | ||
| ---------------------------------- | -------- | ----------------------------------------------------------------------------- | | ||
| **game** | object | [Game Object](objects/game) describing the game being played. | | ||
| **turn** | integer | Final turn number. | | ||
| **board** | object | [Board Object](objects/board) describing the initial state of the game board. | | ||
| **you** | object | [Battlesnake Object](objects/battlesnake) describing your Battlesnake. | | ||
|
||
#### Response Properties | ||
|
||
Responses to this request are ignored by the game engine. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"label": "Objects" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.